package com.laiketui.plugin.common.service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Maps;
import com.laiketui.core.cache.RedisUtil;
import com.laiketui.core.exception.LaiKeAPIException;
import com.laiketui.core.lktconst.GloabConst;
import com.laiketui.core.utils.okhttp.HttpUtils;
import com.laiketui.core.utils.tool.DoubleFormatUtil;
import com.laiketui.plugin.common.domain.MainVo;
import com.laiketui.plugin.common.domain.base.*;
import com.laiketui.plugin.common.domain.base.goods.FreightModel;
import com.laiketui.plugin.common.domain.base.group.GroupOpenModel;
import com.laiketui.plugin.common.domain.base.log.AdminRecordModel;
import com.laiketui.plugin.common.domain.base.order.ExpressDeliveryModel;
import com.laiketui.plugin.common.domain.base.order.OrderConfigModal;
import com.laiketui.plugin.common.domain.base.payment.PaymentModel;
import com.laiketui.plugin.common.domain.base.presell.PreSellConfigModel;
import com.laiketui.plugin.common.domain.base.seckill.SecondsConfigModel;
import com.laiketui.plugin.common.domain.base.user.UserAddress;
import com.laiketui.plugin.common.domain.lktconst.DictionaryConst;
import com.laiketui.plugin.common.domain.lktconst.ErrorCode;
import com.laiketui.plugin.common.domain.vo.AdminOrderListVo;
import com.laiketui.plugin.common.domain.vo.OrderSettlementVo;
import com.laiketui.plugin.common.domain.vo.OrderVo;
import com.laiketui.plugin.common.domain.vo.freight.DefaultFreightVO;
import com.laiketui.plugin.common.domain.vo.freight.FreightRuleVO;
import com.laiketui.plugin.common.domain.vo.order.AdminOrderDetailVo;
import com.laiketui.plugin.common.domain.vo.order.OrderModifyVo;
import com.laiketui.plugin.common.domain.vo.sec.AdminDeliveryVo;
import com.laiketui.plugin.common.domain.vo.sec.EditOrderVo;
import com.laiketui.plugin.common.interfaces.PublicMchService;
import com.laiketui.plugin.common.interfaces.PublicOrderService;
import com.laiketui.plugin.common.interfaces.PublicRefundService;
import com.laiketui.plugin.common.interfaces.PubliceService;
import com.laiketui.plugin.common.interfaces.order.PublicExpressService;
import com.laiketui.plugin.common.interfaces.pay.PublicPaymentConfigService;
import com.laiketui.plugin.common.mapper.*;
import com.laiketui.plugin.common.tool.DataUtils;
import com.laiketui.plugin.common.tool.DateUtil;
import com.laiketui.plugin.common.tool.OrderDataUtils;
import com.laiketui.plugin.common.tool.SplitUtils;
import com.laiketui.plugin.common.tool.cache.RedisDataTool;
import com.laiketui.plugin.common.tool.data.GoodsDataUtils;
import com.laiketui.plugin.common.tool.data.SerializePhpUtils;
import com.laiketui.plugin.common.tool.http.HttpApiUtils;
import com.laiketui.plugin.common.tool.str.StringUtils;
import com.laiketui.root.license.Md5Util;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.time.FastDateFormat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.*;



/**
 * 订单通用服务类
 *
 * @author wangxian
 */
@Service
public class PublicOrderServiceImpl implements PublicOrderService {

    private final Logger logger = LoggerFactory.getLogger(PublicOrderServiceImpl.class);

    @Autowired
    private OrderModelMapper orderModelMapper;

    @Autowired
    private DistributionRecordModelMapper distributionRecordModelMapper;

    @Autowired
    private ReturnOrderModelMapper returnOrderModelMapper;

    @Autowired
    private OrderDetailsModelMapper orderDetailsModelMapper;

    @Autowired
    private ExpressModelMapper expressModelMapper;

    @Autowired
    private PaymentModelMapper paymentModelMapper;

    @Autowired
    private PubliceService publiceService;

    @Autowired
    private FreightModelMapper freightModelMapper;

    @Autowired
    private SecondsConfigModelMapper secondsConfigModelMapper;

    @Autowired
    private OrderConfigModalMapper orderConfigModalMapper;

    @Autowired
    private AdminCgModelMapper adminCgModelMapper;

    @Autowired
    private PreSellRecordModelMapper preSellRecordModelMapper;

    @Autowired
    private IntegralGoodsModelMapper integralGoodsModelMapper;

    @Autowired
    private ExpressDeliveryModelMapper expressDeliveryModelMapper;

    @Autowired
    private CustomerModelMapper customerModelMapper;


    @Override
    public Map<String, Object> getSettlementOrderList(OrderSettlementVo vo) throws LaiKeAPIException {
        Map<String, Object> resultMap = new HashMap<>(16);
        try {
            Map<String, Object> parmaMap = new HashMap<>(16);
            BigDecimal allPrice = BigDecimal.ZERO;
            parmaMap.put("store_id", vo.getStoreId());
            if (vo.getMchId() != null) {
                parmaMap.put("mchId", vo.getMchId());
            }
            //结算订单只显示已完成的订单
            List<Integer> statusList = new ArrayList<>();
            statusList.add(DictionaryConst.OrdersStatus.ORDERS_R_STATUS_COMPLETE);
            statusList.add(DictionaryConst.OrdersStatus.ORDERS_R_STATUS_CLOSE);
            parmaMap.put("statusList", statusList);
            parmaMap.put("add_time_sort", DataUtils.Sort.DESC.toString());
            parmaMap.put("start", vo.getPageNo());
            parmaMap.put("pagesize", vo.getPageSize());
            //是否结算
            if (vo.getStatus() != null) {
                if (vo.getStatus() == 1) {
                    //已结算
                    parmaMap.put("settlement_status", OrderDetailsModel.SETTLEMENT_TYPE_SETTLED);
                } else {
                    //未结算
                    parmaMap.put("settlement_status", OrderDetailsModel.SETTLEMENT_TYPE_UNSETTLED);
                }
            }

            parmaMap.put("orderId", vo.getId());
            parmaMap.put("mch_id", vo.getId());
            if (StringUtils.isNotEmpty(vo.getSearch())) {
                parmaMap.put("search", vo.getSearch());
            }
            if (StringUtils.isNotEmpty(vo.getStartDate())) {
                parmaMap.put("startdate", vo.getStartDate());
            }
            if (StringUtils.isNotEmpty(vo.getEndDate())) {
                parmaMap.put("enddate", vo.getEndDate());
            }
            if (StringUtils.isNotEmpty(vo.getMchName())) {
                parmaMap.put("mch_name", vo.getMchName());
            }
            //订单类型
            if (StringUtils.isNotEmpty(vo.getOrderType())) {
                parmaMap.put("orderType", vo.getOrderType());
                if (vo.getOrderType().equals(DictionaryConst.OrdersType.ORDERS_HEADER_PT)){
                    //显示拼团成功的 禅道48500
                    parmaMap.put("groupStatus", GroupOpenModel.Status.GROUP_GOODS_STATUS_SUCCESS.getKey());
                    //禅道 52057
                    if (StringUtils.isNotEmpty(vo.getStartDate())) {
                        parmaMap.put("settlement_StartDate", vo.getStartDate());
                    }
                    if (StringUtils.isNotEmpty(vo.getEndDate())) {
                        parmaMap.put("settlement_StartDate", vo.getEndDate());
                    }
                }
            }
            parmaMap.put("group_sNo", "group_sNo");
            //获取全部已结算/待结算的金额
            allPrice = orderModelMapper.getOrderAllPrice(parmaMap);
            int total = orderModelMapper.countAdminOrderList(parmaMap);
            List<Map<String, Object>> orderList = new ArrayList<>();
            if (total > 0) {
                orderList = orderModelMapper.adminOrderList(parmaMap);
                for (Map<String, Object> map : orderList) {
                    String orderType = MapUtils.getString(map, "otype");
                    String orderNo = MapUtils.getString(map, "sNo");
                    String couponPrice = map.get("coupon_price") + "";
                    if (StringUtils.isEmpty(couponPrice)) {
                        couponPrice = "0";
                    }
                    //是否结算标识settlement_status
                    Integer isSettlement = MapUtils.getInteger(map, "settlement_status");
                    int status = MapUtils.getIntValue(map, "status");
                    //佣金
                    BigDecimal commission = new BigDecimal("0");
                    //退还佣金
                    BigDecimal rcommission = new BigDecimal("0");
                    //如果是分销订单则佣金计算
                    if (DictionaryConst.OrdersType.ORDERS_HEADER_FX.equalsIgnoreCase(orderType)) {
                        //类型 1:转入(收入) 2:提现 3:个人进获奖8:充值积分
                        commission = distributionRecordModelMapper.sumEstimateAmtByType(1, orderNo);
                        rcommission = distributionRecordModelMapper.sumEstimateAmtByType(9, orderNo);
                    }
                    //退款金额
                    BigDecimal returnAmt = returnOrderModelMapper.getReturnAmtByOrder(orderNo);
                    map.put("commission", commission);
                    map.put("r_commission", rcommission);
                    map.put("return_money", returnAmt);
                    //优惠金额(该金额是总优惠券金额 平台+店铺)
                    BigDecimal mchDisAmt = new BigDecimal(couponPrice);
                    //平台优惠金额
                    BigDecimal dicPrice = new BigDecimal(MapUtils.getString(map, "preferential_amount", "0"));
                    if (BigDecimal.ZERO.compareTo(dicPrice) < 0) {
                        //如果用了平台优惠券 则店铺优惠券 = 总优惠券金额-平台优惠金额
                        mchDisAmt = mchDisAmt.subtract(dicPrice);
                    }
                    map.put("mch_discount", mchDisAmt);
                    map.put("preferential_amount", dicPrice);
                    map.put("arrive_time", DateUtil.dateFormate(MapUtils.getString(map, "arrive_time"), GloabConst.TimePattern.YMDHMS));

                    BigDecimal settlementPrice = BigDecimal.ZERO;
                    String statusName = "待结算";
                    if (OrderDetailsModel.SETTLEMENT_TYPE_SETTLED.equals(isSettlement)) {
                        statusName = "已结算";
                        //结算金额 订单金额就是结算金额
                        settlementPrice = new BigDecimal(MapUtils.getString(map, "z_price"));
                    }
                    map.put("settlementPrice", settlementPrice);
                    map.put("status_name", statusName);
                    map.put("add_time", DateUtil.dateFormate(MapUtils.getString(map, "add_time"), GloabConst.TimePattern.YMDHMS));
                }
            }
            resultMap.put("allPrice", allPrice);
            resultMap.put("list", orderList);
            resultMap.put("total", total);
        } catch (Exception e) {
            logger.error("获取订单信息 异常:", e);
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_WLYC, "网络异常");
        }
        return resultMap;
    }

    @Override
    public Map<String, Object> pcMchOrderIndex(AdminOrderListVo vo) throws LaiKeAPIException {
        Map<String, Object> resultMap = new HashMap<>(16);
        try {
            Map<String, Object> parmaMap = new HashMap<>(16);
            parmaMap.put("store_id", vo.getStoreId());
            parmaMap.put("operation_type", vo.getOperationType());
            if (StringUtils.isNotEmpty(vo.getKeyWord())) {
                parmaMap.put("sNo", vo.getKeyWord());
            }
            if (vo.getMchId() != null) {
                parmaMap.put("mchId", vo.getMchId());
            }
            //特殊订单
            if (vo.getSelfLifting() != null) {
                Integer selfLifting = 0;
                String orderType = null;
                List<String> list = new ArrayList<>();
                switch (vo.getSelfLifting()) {
                    case 0:
                        orderType = DictionaryConst.OrdersType.ORDERS_HEADER_GM;
                        selfLifting = null;
                        break;
                    case 1:
                        orderType = DictionaryConst.OrdersType.ORDERS_HEADER_GM;
                        break;
                    case 3:
                        orderType = DictionaryConst.OrdersType.ORDERS_HEADER_VI;
                        break;
                    case 4:
                        list.add(DictionaryConst.OrdersType.ORDERS_HEADER_GM);
                        list.add(DictionaryConst.OrdersType.ORDERS_HEADER_VI);
                        parmaMap.put("orderTypeList_not", list);
                        break;
                    case 2:
                        selfLifting = 1;
                        break;
                    case 6:
                        orderType = DictionaryConst.OrdersType.ORDERS_HEADER_JP;
                        break;
                    case 7:
                        orderType = DictionaryConst.OrdersType.ORDERS_HEADER_IN;
                        break;
                    case 8:
                        orderType = DictionaryConst.OrdersType.ORDERS_HEADER_MS;
                        if (StringUtils.isNotEmpty(vo.getPluginSelfLifting())){
                            selfLifting = vo.getPluginSelfLifting();
                        }else {
                            selfLifting = null;
                        }
                        break;
                    case 9:
                        //只显示拼团成功的订单
                        orderType = DictionaryConst.OrdersType.ORDERS_HEADER_PT;
                        parmaMap.put("groupStatus", GroupOpenModel.Status.GROUP_GOODS_STATUS_SUCCESS.getKey());
                        parmaMap.put("noStatus", String.valueOf(DictionaryConst.OrdersStatus.ORDERS_R_STATUS_UNPAID));
                        break;
                    case 11:
                        //限时折扣
                        orderType = DictionaryConst.OrdersType.ORDERS_HEADER_FS;
                        break;
                    case 20:
                        //拼团特殊处理-只显示拼团成功的订单
                        List<Integer> groupStatus = new ArrayList<>();
                        //拼团  -》禅道48417 增加拼团失败订单
                        groupStatus.add(GroupOpenModel.Status.GROUP_GOODS_STATUS_SUCCESS.getKey());
                        groupStatus.add(GroupOpenModel.Status.GROUP_GOODS_STATUS_FAIL.getKey());
                        parmaMap.put("groupStatusList", groupStatus);
                        //拼团创建不显示待付款订单  禅道45216
                        parmaMap.put("noStatus", String.valueOf(DictionaryConst.OrdersStatus.ORDERS_R_STATUS_UNPAID));
                        break;
                    case 21:
                        //h5拼团店铺特殊处理-只显示拼团失败的订单
                        orderType = DictionaryConst.OrdersType.ORDERS_HEADER_PT;
                        parmaMap.put("groupStatus", GroupOpenModel.Status.GROUP_GOODS_STATUS_FAIL.getKey());
                        parmaMap.put("noStatus", String.valueOf(DictionaryConst.OrdersStatus.ORDERS_R_STATUS_UNPAID));
                        break;

                }
                if (list.size() == 0) {
                    parmaMap.put("orderType", orderType);
                }
                if (selfLifting != null) {
                    parmaMap.put("self_lifting", selfLifting);
                }
            }
            //禅道49609 -》用户、商家、平台删除自己的订单
            if (vo.getStoreType() == GloabConst.StoreType.STORE_TYPE_PC_ADMIN){
                parmaMap.put("storeRecycle", OrderModel.SHOW);
            }else if (vo.getStoreType() == GloabConst.StoreType.STORE_TYPE_PC_MCH
                    || vo.getStoreType() == GloabConst.StoreType.STORE_TYPE_APP
                    || vo.getStoreType() == GloabConst.StoreType.STORE_TYPE_H5
                    || vo.getStoreType() == GloabConst.StoreType.STORE_TYPE_WX_MP){
                parmaMap.put("mchRecycle", OrderModel.SHOW);
            }
            parmaMap.put("mch_name", vo.getMchName());
            parmaMap.put("ostatus", vo.getStatus());
            parmaMap.put("startdate", vo.getStartDate());
            parmaMap.put("enddate", vo.getEndDate());
            parmaMap.put("start", vo.getPageNo());
            parmaMap.put("pagesize", vo.getPageSize());
            parmaMap.put("group_sNo", "group_sNo");
            parmaMap.put("add_time_sort", DataUtils.Sort.DESC.toString());
            if (vo.getId() != null) {
                parmaMap.put("orderId", vo.getId());
            }

            List<Map<String, Object>> resultList = new ArrayList<>();

            int total = orderModelMapper.countAdminOrderList(parmaMap);
            List<Map<String, Object>> orderList = new ArrayList<>();
            if (total > 0) {
                orderList = orderModelMapper.adminOrderList(parmaMap);
            }
            for (Map<String, Object> map : orderList) {
                String orderNo = MapUtils.getString(map, "sNo");
                //订单商品个数
                int goodsNum = MapUtils.getIntValue(map, "goodsNum");

                //导出需要导出明细,如果导出明细则会导致数量与前台不一致,这里先查询是否有多条明细,如果当前订单有多条明细则把明细放入集合
                if (vo.getExportType().equals(1)) {
                    Map<String, Object> orderParamMap = new HashMap<>(16);
                    orderParamMap.put("orderNo1", orderNo);
                    orderParamMap.put("group_detail_id", "group_detail_id");
                    OrderDetailsModel orderDetailsModel = new OrderDetailsModel();
                    orderDetailsModel.setR_sNo(orderNo);
                    int count = orderDetailsModelMapper.selectCount(orderDetailsModel);
                    if (count > 1) {
                        List<Map<String, Object>> orderDetailList = orderModelMapper.adminOrderList(orderParamMap);
                        for (Map<String, Object> detailMap : orderDetailList) {
                            detailMap.put("goodsNum", goodsNum);
                            pcMchOrderIndex(detailMap, vo.getStoreId(), resultList);
                        }
                        continue;
                    }
                }
                //导出end
                pcMchOrderIndex(map, vo.getStoreId(), resultList);
            }

            resultMap.put("total", total);
            resultMap.put("list", resultList);
        } catch (Exception e) {
            logger.error("订单列表 异常", e);
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_WLYC, "网络异常", "pcMchOrderIndex");
        }
        return resultMap;
    }

    //订单列表辅助方法
    private void pcMchOrderIndex(Map<String, Object> map, int storeId, List<Map<String, Object>> resultList) {
        try {
            Map<String, Object> res = new HashMap<>(16);
            //订单ID
            res.put("id", MapUtils.getString(map, "id"));
            //子订单ID
            res.put("orderDetailIds", MapUtils.getString(map, "detailId"));
            res.put("haveReturnOrder", DictionaryConst.WhetherMaven.WHETHER_NO);
            //判断有无售后未结束
            int unFinishShouHouOrderNum = returnOrderModelMapper.orderDetailReturnIsNotEnd(storeId, MapUtils.getString(map, "sNo"),  MapUtils.getIntValue(map, "detailId"));
            //有售后未结束不能发货
            if (unFinishShouHouOrderNum > 0){
                res.put("haveReturnOrder", DictionaryConst.WhetherMaven.WHETHER_OK);
            }
            res.put("detailId", MapUtils.getString(map, "detailId"));
            //店铺订单号
            res.put("orderno", MapUtils.getString(map, "sNo"));
            //上游商户订单号
            res.put("mchOrderNo", MapUtils.getString(map, "real_sno"));
            res.put("createDate", DateUtil.dateFormate(MapUtils.getString(map, "add_time"), GloabConst.TimePattern.YMDHMS));
            //店铺名称
            res.put("mchName", MapUtils.getString(map, "shopName"));
            //商品名称
            res.put("goodsName", MapUtils.getString(map, "product_title"));
            //商品图片
            String imgUrl = publiceService.getImgPath(MapUtils.getString(map, "img"), storeId);
            res.put("goodsImgUrl", imgUrl);
            //处理规格
            String attrStr = GoodsDataUtils.getProductSkuValue(MapUtils.getString(map, "attribute"));
            res.put("attrStr", attrStr);
            //子订单商品数量 订单表
            res.put("needNum", MapUtils.getString(map, "needNum"));
            //商品总数量
            res.put("num", MapUtils.getString(map, "num"));
            //规格属性价格 规格属性表
            res.put("goodsPrice", MapUtils.getString(map, "goodsAmt"));
            //订单总价 订单表
            res.put("orderPrice", MapUtils.getString(map, "z_price"));
            res.put("detailGoodsPrice", MapUtils.getString(map, "detail_goods_price"));
            //下单类型1用户下单2店铺下单3平台下单
            res.put("operation_type", MapUtils.getString(map, "operation_type"));
            //订单状态
            res.put("status", OrderDataUtils.getOrderStatus(MapUtils.getIntValue(map, "status")));
            //订单类型
            res.put("otype", OrderDataUtils.getOrderType(MapUtils.getString(map, "otype")));
            //订单商品数量
            res.put("goodsNum", MapUtils.getString(map, "goodsNum"));
            //优惠后的金额
            res.put("after_discount", MapUtils.getString(map, "after_discount"));
            //积分
            res.put("allow", String.format("%.0f", new BigDecimal(MapUtils.getString(map, "after_discount"))));
            //支付积分
            res.put("orderAllow", String.format("%.0f", new BigDecimal(MapUtils.getString(map, "allow"))));
            //支付方式
            String payType = MapUtils.getString(map, "pay");
            res.put("pay", payType);
            if (StringUtils.isNotEmpty(payType)) {
                PaymentModel paymentModel = new PaymentModel();
                paymentModel.setClass_name(payType);
                paymentModel = paymentModelMapper.selectOne(paymentModel);
                if (paymentModel != null) {
                    payType = paymentModel.getName();
                }
            }
            res.put("payName", payType);
            res.put("userId", MapUtils.getString(map, "user_id"));
            res.put("userName", MapUtils.getString(map, "name"));
            //获取物流信息
            StringBuffer wuliuStr = new StringBuffer(SplitUtils.DH);
            List<Map<String, Object>> mapList = orderDetailsModelMapper.selectStoreOrderDetails(storeId, MapUtils.getString(map, "sNo"));
            if (mapList.size() > 0) {
                mapList.forEach(expressStr -> {
                    Integer exId = MapUtils.getInteger(expressStr, "express_id");
                    ExpressModel expressModel = expressModelMapper.selectByPrimaryKey(exId);
                    if (expressModel != null) {
                        String logistics = String.format("%s(%s)", MapUtils.getString(expressStr, "courier_num"), expressModel.getKuaidi_name());
                        wuliuStr.append(logistics).append(SplitUtils.DH);
                    }
                });
            }
            res.put("expressStr", wuliuStr);
            res.put("expressList", StringUtils.trim(wuliuStr.toString(), SplitUtils.DH).split(SplitUtils.DH));
            res.put("mobile", MapUtils.getString(map, "mobile"));
            String addressInfo = MapUtils.getString(map, "address");
            res.put("address", addressInfo);
            String sheng = MapUtils.getString(map, "sheng"), shi = MapUtils.getString(map, "shi"), xian = MapUtils.getString(map, "xian");
            res.put("addressInfo", sheng + shi + xian + addressInfo);
            res.put("courier_num", MapUtils.getString(map, "courier_num"));
            res.put("freight", MapUtils.getString(map, "freight"));
            res.put("shopName", MapUtils.getString(map, "shopName"));
            //运输方式
            res.put("selfLiftingName", MapUtils.getIntValue(map, "self_lifting") == 0 ? "快递" : "自提");
            //商品id
            res.put("goodsId", MapUtils.getInteger(map, "goodsId"));
            res.put("old_total", MapUtils.getString(map, "old_total"));
            res.put("old_freight", MapUtils.getString(map, "old_freight"));
            resultList.add(res);
        } catch (Exception e) {
            logger.error("订单列表 异常", e);
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_WLYC, "网络异常", "pcMchOrderIndex");
        }
    }

    @Override
    public void updateOrderState(int storeId, String orderno) throws LaiKeAPIException {
        try {
            //获取订单明细
            OrderDetailsModel orderDetailsModel = new OrderDetailsModel();
            orderDetailsModel.setStore_id(storeId);
            orderDetailsModel.setR_sNo(orderno);
            List<OrderDetailsModel> orderDetailsModelList = orderDetailsModelMapper.select(orderDetailsModel);
            Set<Integer> orderStateList = new HashSet<>();
            for (OrderDetailsModel orderDetails : orderDetailsModelList) {
                orderStateList.add(orderDetails.getR_status());
            }
            //判断订单商品是否都是同一个状态
            if (orderStateList.size() == 1) {
                //获取主表状态
                OrderModel orderModel = new OrderModel();
                orderModel.setsNo(orderno);
                orderModel = orderModelMapper.selectOne(orderModel);
                if (orderModel != null) {
                    if (orderStateList.contains(orderModel.getStatus())) {
                        logger.debug("订单商品状态和订单总状态都处于统一状态,无需修改");
                    } else {
                        //修订主表状态
                        OrderModel updateOrder = new OrderModel();
                        updateOrder.setId(orderModel.getId());
                        updateOrder.setStatus(orderStateList.iterator().next());
                        //如果都是关闭状态,则标记订单已经结算
                        if (orderStateList.contains(DictionaryConst.OrdersStatus.ORDERS_R_STATUS_CLOSE)) {
                            updateOrder.setSettlement_status(OrderDetailsModel.SETTLEMENT_TYPE_SETTLED);
                            //结算时间
                            updateOrder.setArrive_time(new Date());
                        }
                        int count = orderModelMapper.updateByPrimaryKeySelective(updateOrder);
                        if (count < 1) {
                            logger.debug("修订订单主表状态失败 参数:" + JSON.toJSONString(updateOrder));
                        } else {
                            logger.debug("修订订单主表状态成功 参数:" + JSON.toJSONString(updateOrder));
                        }
                    }
                } else {
                    throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_DDBCZ, "订单不存在", "updateOrderState");
                }
            } else {
                logger.debug("订单商品状态没有处于统一状态,无需修改");
            }
        } catch (Exception e) {
            logger.error("修改订单状态 异常", e);
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_WLYC, "网络异常", "updateOrderState");
        }
    }

    @Override
    public String createOrderNo(String orderType) {
        try {
            if (StringUtils.isEmpty(orderType)) {
                orderType = DictionaryConst.OrdersType.ORDERS_HEADER_GM;
            }
            StringBuilder sNo = new StringBuilder();
            Random random = new Random();
            sNo.append(orderType).append(FastDateFormat.getInstance(GloabConst.TimePattern.YMDHMS2).format(new Date())).append(random.nextInt(9))
                    .append(random.nextInt(9)).append(random.nextInt(9)).append(random.nextInt(9))
                    .append(random.nextInt(9)).append(random.nextInt(9));
            OrderModel orderModel = new OrderModel();
            orderModel.setsNo(sNo.toString());
            orderModel = orderModelMapper.selectOne(orderModel);
            if (orderModel == null) {
                return sNo.toString();
            } else {
                return createOrderNo(orderType);
            }
        } catch (Exception e) {
            logger.error(e.getMessage());
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_CJDDHSB, "创建订单号失败", "createOrderNo");
        }
    }


    @Override
    public Map<String, Object> getFreight(Map<String, List<Map<String, Object>>> freightMap, List<Map<String, Object>> products, UserAddress userAddress, int storeId, String productType) {
        Map<String, Object> resultMap = new HashMap<>();
        try {
            double yunfei = 0.0;
            int productNum = 0;
            //是否开启了包邮设置
            int packageSettings = 0;
            //
            boolean orderYunfei = false;
            //同件
            int samePiece = 0;
            //同单
            Integer sameOrder = null;
            if (DictionaryConst.OrdersType.ORDERS_HEADER_MS.equals(productType)) {
                SecondsConfigModel secondsConfigModel = new SecondsConfigModel();
                secondsConfigModel.setStore_id(storeId);
                secondsConfigModel = secondsConfigModelMapper.selectOne(secondsConfigModel);
                if (secondsConfigModel != null) {
                    packageSettings = secondsConfigModel.getPackage_settings();
                    // 同件
                    samePiece = secondsConfigModel.getSame_piece();
                }
            } else {
                OrderConfigModal orderConfigModal = new OrderConfigModal();
                orderConfigModal.setStore_id(storeId);
                orderConfigModal = orderConfigModalMapper.selectOne(orderConfigModal);
                if (orderConfigModal != null) {
                    packageSettings = orderConfigModal.getPackage_settings();
                    // 同件
                    samePiece = orderConfigModal.getSame_piece();
                    // 同单
                    sameOrder = orderConfigModal.getSame_order();
                }
            }
            //店铺id集合
            Set<String> keys = freightMap.keySet();
            // 开启包邮设置
            if (packageSettings == 1) {
                for (String key : keys) {
                    List<Map<String, Object>> productFreights = freightMap.get(key);
                    for (Map<String, Object> productFreight : productFreights) {
                        int num = MapUtils.getInteger(productFreight, "num");
                        productNum += num;
                        if (samePiece <= num) {
                            productFreight.put("order_yunfei", true);
                        } else {
                            productFreight.put("order_yunfei", false);
                        }

                        if (sameOrder != null && productNum >= sameOrder) {
                            orderYunfei = true;
                        }
                    }
                }
            } else {
                for (String key : keys) {
                    List<Map<String, Object>> productFreights = freightMap.get(key);
                    for (Map<String, Object> productFreight : productFreights) {
                        productFreight.put("order_yunfei", false);
                    }
                }
            }

            if (orderYunfei) {
                //满足免邮条件
                for (Map<String, Object> product : products) {
                    product.put("freight", 0.0);
                }
            } else {
                //各个店铺下商品所需的运费
                Map<String, Object> freightIdMap = new HashMap<>();
                for (String key : keys) {
                    //运费信息
                    resultMap.put("freight_id", freightIdMap);
                    List<Map<String, Object>> productFreights = freightMap.get(key);
                    for (Map<String, Object> productFreight : productFreights) {
                        //获取运费模版id
                        Integer freightIdObj = MapUtils.getInteger(productFreight, "freight_id");
                        //单件运费
                        boolean singlProductYunfei = (boolean) productFreight.get("order_yunfei");
                        FreightModel freightModel = new FreightModel();
                        if (freightIdObj != null) {
                            BigDecimal freightId = BigDecimal.valueOf(freightIdObj);
                            freightModel.setId(freightId.intValue());
                        } else {
                            freightModel.setMch_id(Integer.parseInt(key));
                            freightModel.setStore_id(storeId);
                            freightModel.setIs_default(1);
                        }
                        freightModel = freightModelMapper.selectOne(freightModel);
                        if (freightModel != null) {
                            //单个商品免运费
                            if (singlProductYunfei) {
                                yunfei = 0;
                                List<Double> mchProductFreigths = new ArrayList<>();
                                if (freightIdMap.containsKey(key)) {
                                    mchProductFreigths = DataUtils.cast(freightIdMap.get(key));
                                    if (mchProductFreigths == null) {
                                        mchProductFreigths = new ArrayList<>();
                                    }
                                }
                                mchProductFreigths.add(0.0);
                                freightIdMap.put(key, mchProductFreigths);
                            } else {
                                //获取运费
                                BigDecimal goodsYunFei = this.getFreight(freightModel.getId(), userAddress);
                                //计算总运费
                                yunfei += goodsYunFei.doubleValue();
                                List<Double> mchProductFreigths = new ArrayList<>();
                                mchProductFreigths.add(goodsYunFei.doubleValue());
                                freightIdMap.put(key, mchProductFreigths);
                            }
                        }
                    }
                }
            }

            resultMap.put("yunfei", yunfei);
            resultMap.put("freight_ids", resultMap.get("freight_id"));

            if (DictionaryConst.OrdersType.ORDERS_HEADER_JP.equals(productType)) {
                for (Map<String, Object> product : products) {
                    product.put("freight_price", yunfei);
                }
            } else {
                Map<String, List<Double>> freight_ids = DataUtils.cast(resultMap.get("freight_ids"));
                //计算各个店铺下商品的运费
                for (Map<String, Object> mchProduct : products) {
                    BigDecimal freight_price_total = BigDecimal.ZERO;
                    BigDecimal products_num = BigDecimal.ZERO;
                    int shop_id = (int) mchProduct.get("shop_id");

                    List<Map<String, Object>> onlyProductsInfo = DataUtils.cast(mchProduct.get("list"));
                    if (onlyProductsInfo == null) {
                        onlyProductsInfo = new ArrayList<>();
                    }
                    //纯商品信息
                    int pos = 0;
                    for (Map<String, Object> productInfo : onlyProductsInfo) {
                        BigDecimal freight_price = BigDecimal.ZERO;
                        products_num = products_num.add(new BigDecimal(productInfo.get("num") + ""));
                        if (freight_ids != null) {
                            List<Double> shopGoodsYunFeiList = freight_ids.get(shop_id + "");
                            logger.debug("计算订单运费 当前店铺{},当前店铺商品集运费{}", shop_id, JSON.toJSONString(shopGoodsYunFeiList));
                            if (shopGoodsYunFeiList != null && shopGoodsYunFeiList.size() > pos) {
                                freight_price = freight_price.add(new BigDecimal(shopGoodsYunFeiList.get(pos++).toString()));
                                freight_price_total = freight_price_total.add(freight_price);
                            }
                        }
                        productInfo.put("freight_price", freight_price);
                    }
                    mchProduct.put("freight_price", DoubleFormatUtil.format(freight_price_total.doubleValue()));
                    mchProduct.put("products_num", products_num);
                    Double mchProductTotal = (Double) mchProduct.get("product_total");
                    mchProduct.put("product_total", DoubleFormatUtil.format(mchProductTotal));
                }
            }
            resultMap.put("products", products);
        } catch (Exception e) {
            logger.error("运费计算失败 异常", e);
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_YFJSSB, "运费计算失败", "getFreight");
        }
        return resultMap;
    }

    @Override
    public BigDecimal getFreight(Integer goodsAddressId, UserAddress userAddress) throws LaiKeAPIException {
        BigDecimal yunfei = new BigDecimal("0");
        try {
            if (goodsAddressId == null) {
                return yunfei;
            }
            //获取商品运费模板信息
            FreightModel freightModel = freightModelMapper.selectByPrimaryKey(goodsAddressId);
            if (freightModel != null && userAddress != null) {
                Map<Integer, LinkedHashMap<String, Object>> dataMap = SerializePhpUtils.getUnSerializeByFreight(freightModel.getFreight());
                for (Integer key : dataMap.keySet()) {
                    LinkedHashMap<String, Object> yufeiMap = dataMap.get(key);
                    if (yufeiMap.isEmpty()) {
                        continue;
                    }
                    //参数列表
                    Map<String, Object> parmaMap = new HashMap<>(16);
                    //获取地区名称
                    String[] nameList = yufeiMap.get("name").toString().split(",");
                    parmaMap.put("nameList", nameList);
                    //获取运费信息
                    List<Map<String, Object>> freightInfoList = adminCgModelMapper.getAdminCgInfoDynamic(parmaMap);
                    for (Map<String, Object> map : freightInfoList) {
                        String name = map.get("G_CName").toString();
                        if (name.equals(userAddress.getSheng())) {
                            yunfei = new BigDecimal(yufeiMap.get("one").toString());
                            break;
                        }
                    }
                }
            }
        } catch (LaiKeAPIException e) {
            throw e;
        } catch (Exception e) {
            logger.debug("运费计算 异常", e);
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_YFJSSB, "运费计算失败", "getFreight");
        }
        return yunfei;
    }


    @Override
    public BigDecimal getFreight(Integer goodsAddressId, UserAddress userAddress, int productNum, BigDecimal weightNum) throws LaiKeAPIException {
        BigDecimal yunfei = BigDecimal.ZERO;
        BigDecimal weightNumCount = weightNum.multiply(new BigDecimal(productNum));
        try {
            if (goodsAddressId == null) {
                return yunfei;
            }
            //获取商品运费模板信息
            FreightModel freightModel = freightModelMapper.selectByPrimaryKey(goodsAddressId);
            if (freightModel != null && userAddress != null) {
                //新运费规则：有指定运费规则并且用户地址在指定运费规则地区中就按指定运费计算 反之计算默认运费规则
                String address = userAddress.getSheng() + "-" + userAddress.getCity() + "-" + userAddress.getQuyu();
                if (StringUtils.isNotEmpty(freightModel.getFreight())) {
                    List<String> freightAddress = new ArrayList<>();
                    List<FreightRuleVO> freightRuleVOS = JSON.parseArray(freightModel.getFreight(), FreightRuleVO.class);
                    freightRuleVOS.stream().forEach(freightRuleVO -> {
                        List<String> stringList = Arrays.asList(freightRuleVO.getName().split(com.laiketui.core.common.SplitUtils.DH));
                        freightAddress.addAll(stringList);
                    });
                    if (freightAddress.contains(address)) {
                        //计算指定运费规则
                        for (FreightRuleVO freightRuleVO : freightRuleVOS) {
                            if (Objects.isNull(freightRuleVO)) {
                                continue;
                            }
                            List<String> addressList = Arrays.asList(freightRuleVO.getName().split(com.laiketui.core.common.SplitUtils.DH));
                            //获取运费首件件数
                            int SjJs = Integer.parseInt(freightRuleVO.getOne());
                            //获取运费续件件数
                            int XjJs = Integer.parseInt(freightRuleVO.getTwo());
                            //获取首件重量
                            BigDecimal SjWeightYuFei = new BigDecimal(freightRuleVO.getOne());
                            //获取续件重量
                            BigDecimal XjWeightYuFei = new BigDecimal(freightRuleVO.getTwo());
                            //获取首件件数运费
                            BigDecimal SjYuFei = new BigDecimal(freightRuleVO.getFreight());
                            //获取续件件数运费
                            BigDecimal XjYuFei = new BigDecimal(freightRuleVO.getTfreight());
                            //不包邮
                            if (freightModel.getIs_package_settings() == 0) {
                                //类型 件
                                if (freightModel.getType() == 0) {
                                    if (addressList.contains(address) && productNum <= SjJs) {
                                        //                            yunfei = new BigDecimal(yufeiMap.get("one").toString());
                                        yunfei = SjYuFei;
                                        break;
                                    } else if (addressList.contains(address) && productNum <= XjJs) {
                                        yunfei = XjYuFei.add(SjYuFei);
                                        break;
                                    } else if (addressList.contains(address) && productNum > XjJs) {
                                        //商品-首件  <= 续件       首件运费+续件运费
                                        if (productNum - SjJs <= XjJs) {
                                            yunfei = XjYuFei.add(SjYuFei);
                                            break;
                                        }
                                        //商品-首件  > 续件    (商品重量-首件重量)/续件重量   进一取整    首件运费+进一取整*续件运费
                                        if (productNum - SjJs > XjJs) {
                                            BigDecimal JS = (new BigDecimal(productNum).subtract(new BigDecimal(freightRuleVO.getOne()))).divide(new BigDecimal(freightRuleVO.getTwo()), 0, BigDecimal.ROUND_UP);
                                            yunfei = SjYuFei.add(JS.multiply(XjYuFei));
                                            break;
                                        }
                                    } else {
                                        if (addressList.contains(address)) {
                                            yunfei = SjYuFei;
                                            break;
                                        }
                                    }
                                } else if (freightModel.getType() == 1) {//重量
                                    if (addressList.contains(address) && (weightNumCount.compareTo(SjWeightYuFei) != 1)) {
                                        //                            yunfei = new BigDecimal(yufeiMap.get("one").toString());
                                        yunfei = SjYuFei;
                                        break;
                                    } else if (addressList.contains(address) && (weightNumCount.compareTo(XjWeightYuFei) != 1 && weightNumCount.compareTo(SjWeightYuFei) != -1)) {
                                        yunfei = XjYuFei.add(SjYuFei);
                                        break;
                                    } else if (addressList.contains(address) && weightNumCount.compareTo(XjWeightYuFei) == 1) {
                                        //商品-首件  <= 续件       首件运费+续件运费
                                        if ((weightNumCount.subtract(SjWeightYuFei)).compareTo(XjWeightYuFei) != 1) {
                                            yunfei = XjYuFei.add(SjYuFei);
                                            break;
                                        }
                                        //商品-首件  > 续件    (商品重量-首件重量)/续件重量   进一取整    首件运费+进一取整*续件运费
                                        if ((weightNumCount.subtract(SjWeightYuFei)).compareTo(XjWeightYuFei) == 1) {
                                            BigDecimal JYQZ = (weightNumCount.subtract(new BigDecimal(freightRuleVO.getOne()))).divide(new BigDecimal(freightRuleVO.getTwo()), 0, BigDecimal.ROUND_UP);
                                            yunfei = SjYuFei.add(JYQZ.multiply(XjYuFei));
                                            break;
                                        }
                                    } else {
                                        if (addressList.contains(address)) {
                                            yunfei = SjYuFei;
                                            break;
                                        }
                                    }
                                } else {
                                    if (addressList.contains(address)) {
                                        yunfei = SjYuFei;
                                        break;
                                    }
                                }
                            } else {
                                //包邮
                                //类型 件
                                if (freightModel.getType() == 0) {
                                    if (addressList.contains(address) && productNum <= SjJs && StringUtils.isNotEmpty(freightModel.getPackage_settings()) && productNum < Integer.parseInt(freightModel.getPackage_settings())) {
                                        //                            yunfei = new BigDecimal(yufeiMap.get("one").toString());
                                        yunfei = SjYuFei;
                                        break;
                                    } else if (addressList.contains(address) && productNum <= XjJs && StringUtils.isNotEmpty(freightModel.getPackage_settings()) && productNum < Integer.parseInt(freightModel.getPackage_settings())) {
                                        yunfei = XjYuFei.add(SjYuFei);
                                        break;
                                    } else if (addressList.contains(address) && productNum > XjJs && StringUtils.isNotEmpty(freightModel.getPackage_settings()) && productNum < Integer.parseInt(freightModel.getPackage_settings())) {
                                        //商品-首件  <= 续件       首件运费+续件运费
                                        if (productNum - SjJs <= XjJs) {
                                            yunfei = XjYuFei.add(SjYuFei);
                                            break;
                                        }
                                        //商品-首件  > 续件    (商品重量-首件重量)/续件重量   进一取整    首件运费+进一取整*续件运费
                                        if (productNum - SjJs > XjJs) {
                                            BigDecimal JS = (new BigDecimal(productNum).subtract(new BigDecimal(freightRuleVO.getOne()))).divide(new BigDecimal(freightRuleVO.getTwo()), 0, BigDecimal.ROUND_UP);
                                            yunfei = SjYuFei.add(JS.multiply(XjYuFei));
                                            break;
                                        }
                                    } else if (addressList.contains(address) && StringUtils.isNotEmpty(freightModel.getPackage_settings()) && productNum >= Integer.parseInt(freightModel.getPackage_settings())) {
                                        yunfei = new BigDecimal("0.0");
                                        break;
                                    } else {
                                        if (addressList.contains(address) && StringUtils.isNotEmpty(freightModel.getPackage_settings()) && productNum >= Integer.parseInt(freightModel.getPackage_settings())) {
                                            yunfei = new BigDecimal("0.0");
                                            break;
                                        } else {
                                            if (addressList.contains(address)) {
                                                yunfei = SjYuFei;
                                                break;
                                            }
                                        }
                                    }
                                } else if (freightModel.getType() == 1) {//重量
                                    if (addressList.contains(address) && (weightNumCount.compareTo(SjWeightYuFei) != 1) && StringUtils.isNotEmpty(freightModel.getPackage_settings()) && productNum < Integer.parseInt(freightModel.getPackage_settings())) {
                                        //                            yunfei = new BigDecimal(yufeiMap.get("one").toString());
                                        yunfei = SjYuFei;
                                        break;
                                    } else if (addressList.contains(address) && (weightNumCount.compareTo(XjWeightYuFei) != 1 && weightNumCount.compareTo(SjWeightYuFei) != -1) && StringUtils.isNotEmpty(freightModel.getPackage_settings()) && productNum < Integer.parseInt(freightModel.getPackage_settings())) {
                                        yunfei = XjYuFei.add(SjYuFei);
                                        break;
                                    } else if (addressList.contains(address) && weightNumCount.compareTo(XjWeightYuFei) == 1 && StringUtils.isNotEmpty(freightModel.getPackage_settings()) && productNum < Integer.parseInt(freightModel.getPackage_settings())) {
                                        //商品-首件  <= 续件       首件运费+续件运费
                                        if ((weightNumCount.subtract(SjWeightYuFei)).compareTo(XjWeightYuFei) != 1) {
                                            yunfei = XjYuFei.add(SjYuFei);
                                            break;
                                        }
                                        //商品-首件  > 续件    (商品重量-首件重量)/续件重量   进一取整    首件运费+进一取整*续件运费
                                        if ((weightNumCount.subtract(SjWeightYuFei)).compareTo(XjWeightYuFei) == 1) {
                                            BigDecimal JYQZ = (weightNumCount.subtract(new BigDecimal(freightRuleVO.getOne()))).divide(new BigDecimal(freightRuleVO.getTwo()), 0, BigDecimal.ROUND_UP);
                                            yunfei = SjYuFei.add(JYQZ.multiply(XjYuFei));
                                            break;
                                        }
                                    } else if (addressList.contains(address) && StringUtils.isNotEmpty(freightModel.getPackage_settings()) && productNum >= Integer.parseInt(freightModel.getPackage_settings())) {
                                        yunfei = new BigDecimal("0.0");
                                        break;
                                    } else {
                                        if (addressList.contains(address)) {
                                            yunfei = SjYuFei;
                                            break;
                                        }
                                    }
                                } else {
                                    if (addressList.contains(address) && StringUtils.isNotEmpty(freightModel.getPackage_settings()) && productNum >= Integer.parseInt(freightModel.getPackage_settings())) {
                                        yunfei = new BigDecimal("0.0");
                                        break;
                                    } else {
                                        if (addressList.contains(address)) {
                                            yunfei = SjYuFei;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                        return yunfei;
                    }
                }

                //计算默认运费规则
                DefaultFreightVO defaultFreightVO = JSONObject.parseObject(freightModel.getDefault_freight(), DefaultFreightVO.class);
                //获取运费首件件数
                int SjJs = Integer.parseInt(defaultFreightVO.getNum1());
                //获取运费续件件数
                int XjJs = Integer.parseInt(defaultFreightVO.getNum3());
                //获取首件重量
                BigDecimal SjWeightYuFei = new BigDecimal(defaultFreightVO.getNum1());
                //获取续件重量
                BigDecimal XjWeightYuFei = new BigDecimal(defaultFreightVO.getNum3());
                //获取首件件数运费
                BigDecimal SjYuFei = new BigDecimal(defaultFreightVO.getNum2());
                //获取续件件数运费
                BigDecimal XjYuFei = new BigDecimal(defaultFreightVO.getNum4());
                //不包邮
                if (freightModel.getIs_package_settings() == 0) {
                    //类型 件
                    if (freightModel.getType() == 0) {
                        if (productNum <= SjJs) {
                            yunfei = SjYuFei;
                        } else if (productNum <= XjJs) {
                            yunfei = XjYuFei.add(SjYuFei);
                        } else if (productNum > XjJs) {
                            //商品-首件  <= 续件       首件运费+续件运费
                            if (productNum - SjJs <= XjJs) {
                                yunfei = XjYuFei.add(SjYuFei);
                            }
                            //商品-首件  > 续件    (商品重量-首件重量)/续件重量   进一取整    首件运费+进一取整*续件运费
                            if (productNum - SjJs > XjJs) {
                                BigDecimal JS = (new BigDecimal(productNum).subtract(new BigDecimal(defaultFreightVO.getNum1()))).divide(new BigDecimal(defaultFreightVO.getNum3()), 0, BigDecimal.ROUND_UP);
                                yunfei = SjYuFei.add(JS.multiply(XjYuFei));
                            }
                        } else {
                            yunfei = SjYuFei;
                        }
                    } else if (freightModel.getType() == 1) {//重量
                        if ((weightNumCount.compareTo(SjWeightYuFei) != 1)) {
                            //                            yunfei = new BigDecimal(yufeiMap.get("one").toString());
                            yunfei = SjYuFei;
                        } else if ((weightNumCount.compareTo(XjWeightYuFei) != 1 && weightNumCount.compareTo(SjWeightYuFei) != -1)) {
                            yunfei = XjYuFei.add(SjYuFei);
                        } else if (weightNumCount.compareTo(XjWeightYuFei) == 1) {
                            //商品-首件  <= 续件       首件运费+续件运费
                            if ((weightNumCount.subtract(SjWeightYuFei)).compareTo(XjWeightYuFei) != 1) {
                                yunfei = XjYuFei.add(SjYuFei);
                            }
                            //商品-首件  > 续件    (商品重量-首件重量)/续件重量   进一取整    首件运费+进一取整*续件运费
                            if ((weightNumCount.subtract(SjWeightYuFei)).compareTo(XjWeightYuFei) == 1) {
                                BigDecimal JYQZ = (weightNumCount.subtract(new BigDecimal(defaultFreightVO.getNum1()))).divide(new BigDecimal(defaultFreightVO.getNum3()), 0, BigDecimal.ROUND_UP);
                                yunfei = SjYuFei.add(JYQZ.multiply(XjYuFei));
                            }
                        } else {
                            yunfei = SjYuFei;
                        }
                    } else {
                        yunfei = SjYuFei;
                    }
                } else {//包邮
                    //类型 件
                    if (freightModel.getType() == 0) {
                        if (productNum <= SjJs && StringUtils.isNotEmpty(freightModel.getPackage_settings()) && productNum < Integer.parseInt(freightModel.getPackage_settings())) {
                            yunfei = SjYuFei;
                        } else if (productNum <= XjJs && StringUtils.isNotEmpty(freightModel.getPackage_settings()) && productNum < Integer.parseInt(freightModel.getPackage_settings())) {
                            yunfei = XjYuFei.add(SjYuFei);
                        } else if (productNum > XjJs && StringUtils.isNotEmpty(freightModel.getPackage_settings()) && productNum < Integer.parseInt(freightModel.getPackage_settings())) {
                            //商品-首件  <= 续件       首件运费+续件运费
                            if (productNum - SjJs <= XjJs) {
                                yunfei = XjYuFei.add(SjYuFei);
                            }
                            //商品-首件  > 续件    (商品重量-首件重量)/续件重量   进一取整    首件运费+进一取整*续件运费
                            if (productNum - SjJs > XjJs) {
                                BigDecimal JS = (new BigDecimal(productNum).subtract(new BigDecimal(defaultFreightVO.getNum1()))).divide(new BigDecimal(defaultFreightVO.getNum3()), 0, BigDecimal.ROUND_UP);
                                yunfei = SjYuFei.add(JS.multiply(XjYuFei));
                            }
                        } else if (StringUtils.isNotEmpty(freightModel.getPackage_settings()) && productNum >= Integer.parseInt(freightModel.getPackage_settings())) {
                            yunfei = new BigDecimal("0.0");
                        } else {
                            if (StringUtils.isNotEmpty(freightModel.getPackage_settings()) && productNum >= Integer.parseInt(freightModel.getPackage_settings())) {
                                yunfei = new BigDecimal("0.0");
                            } else {
                                yunfei = SjYuFei;
                            }
                        }
                    } else if (freightModel.getType() == 1) {//重量
                        if ((weightNumCount.compareTo(SjWeightYuFei) != 1) && StringUtils.isNotEmpty(freightModel.getPackage_settings()) && productNum < Integer.parseInt(freightModel.getPackage_settings())) {
                            yunfei = SjYuFei;
                        } else if ((weightNumCount.compareTo(XjWeightYuFei) != 1 && weightNumCount.compareTo(SjWeightYuFei) != -1) && StringUtils.isNotEmpty(freightModel.getPackage_settings()) && productNum < Integer.parseInt(freightModel.getPackage_settings())) {
                            yunfei = XjYuFei.add(SjYuFei);
                        } else if (weightNumCount.compareTo(XjWeightYuFei) == 1 && StringUtils.isNotEmpty(freightModel.getPackage_settings()) && productNum < Integer.parseInt(freightModel.getPackage_settings())) {
                            //商品-首件  <= 续件       首件运费+续件运费
                            if ((weightNumCount.subtract(SjWeightYuFei)).compareTo(XjWeightYuFei) != 1) {
                                yunfei = XjYuFei.add(SjYuFei);
                            }
                            //商品-首件  > 续件    (商品重量-首件重量)/续件重量   进一取整    首件运费+进一取整*续件运费
                            if ((weightNumCount.subtract(SjWeightYuFei)).compareTo(XjWeightYuFei) == 1) {
                                BigDecimal JYQZ = (weightNumCount.subtract(new BigDecimal(defaultFreightVO.getNum1()))).divide(new BigDecimal(defaultFreightVO.getNum3()), 0, BigDecimal.ROUND_UP);
                                yunfei = SjYuFei.add(JYQZ.multiply(XjYuFei));
                            }
                        } else if (StringUtils.isNotEmpty(freightModel.getPackage_settings()) && productNum >= Integer.parseInt(freightModel.getPackage_settings())) {
                            yunfei = new BigDecimal("0.0");
                        } else {
                            yunfei = SjYuFei;
                        }
                    } else {
                        if (StringUtils.isNotEmpty(freightModel.getPackage_settings()) && productNum >= Integer.parseInt(freightModel.getPackage_settings())) {
                            yunfei = new BigDecimal("0.0");
                        } else {
                            yunfei = SjYuFei;
                        }
                    }
                }
            }
        } catch (LaiKeAPIException e) {
            throw e;
        } catch (Exception e) {
            logger.debug("运费计算 异常", e);
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_YFJSSB, "运费计算失败", "getFreight");
        }
        return yunfei;
    }


    @Override
    public void adminDelivery(MainVo vo, Integer exId, String exNo, String orderDetailIds) throws LaiKeAPIException {
        try {
            int row;
            //订单明细集
            List<String> orderListIds = Arrays.asList(orderDetailIds.split(","));
            //获取订单信息
            int storeId = vo.getStoreId();
            int len = orderListIds.size();
            //是全部已经发货,如果详单都被发货,则同意修改订单状态为待收货
            boolean batchSend = false;
            //获取当前订单号
            String orderNo;
            OrderDetailsModel orderDetailsOld = new OrderDetailsModel();
            orderDetailsOld.setStore_id(vo.getStoreId());
            orderDetailsOld.setId(Integer.parseInt(orderListIds.get(0)));
            orderDetailsOld = orderDetailsModelMapper.selectOne(orderDetailsOld);
            if (orderDetailsOld == null) {
                throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_XDBCZ, "详单不存在");
            }
            orderNo = orderDetailsOld.getR_sNo();
            //查询订单信息
            OrderModel orderModel = new OrderModel();
            orderModel.setStore_id(vo.getStoreId());
            orderModel.setsNo(orderNo);
            orderModel = orderModelMapper.selectOne(orderModel);
            OrderDetailsModel orderDetailsCount = new OrderDetailsModel();
            orderDetailsCount.setStore_id(vo.getStoreId());
            orderDetailsCount.setR_sNo(orderNo);
            //统计当前订单下有多少商品
            int orderGoodsNum = orderDetailsModelMapper.selectCount(orderDetailsCount);
            //统计当前发货次数
            orderDetailsCount.setR_status(DictionaryConst.OrdersStatus.ORDERS_R_STATUS_DISPATCHED);
            int curSendPos = orderDetailsModelMapper.selectCount(orderDetailsCount);
            //是否已经全部发货
            if (orderGoodsNum == len + curSendPos) {
                //批量发货
                batchSend = true;
            }
            ExpressDeliveryModel expressDeliveryModel;
            //订单明细发货
            for (String id : orderListIds) {
                //修改订单明细 修改明细订单状态为待收货
                OrderDetailsModel orderDetailsModel = new OrderDetailsModel();
                orderDetailsModel.setId(Integer.parseInt(id));
                orderDetailsModel.setR_status(DictionaryConst.OrdersStatus.ORDERS_R_STATUS_DISPATCHED);
                orderDetailsModel.setExpress_id(exId);
                orderDetailsModel.setCourier_num(exNo);
                orderDetailsModel.setDeliver_time(new Date());
                row = orderDetailsModelMapper.updateByPrimaryKeySelective(orderDetailsModel);
                if (row < 1) {
                    logger.debug("订单{} 发货失败,明细id{}", orderNo, id);
                    throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_FHSB, "发货失败");
                }
                orderDetailsModel= orderDetailsModelMapper.selectByPrimaryKey(orderDetailsModel.getId());
                expressDeliveryModel = new ExpressDeliveryModel();
                expressDeliveryModel.setStore_id(storeId);
                expressDeliveryModel.setsNo(orderDetailsModel.getR_sNo());
                expressDeliveryModel.setExpressId(exId);
                expressDeliveryModel.setCourierNum(exNo);
                expressDeliveryModel.setOrderDetailsId(orderDetailsModel.getId());
                expressDeliveryModel.setNum(orderDetailsModel.getNum());
                expressDeliveryModel.setDeliverTime(new Date());
                row = expressDeliveryModelMapper.insertSelective(expressDeliveryModel);

                if (vo.getStoreType()==8 || vo.getStoreType()==7){
                    publiceService.addAdminRecord(vo.getStoreId(), "将订单ID："+orderDetailsModel.getR_sNo()+" 进行了发货",AdminRecordModel.Type.UPDATE, vo.getAccessId());
                }
            }
            //是否都已经完成了发货,完成了发货则修改订单全部状态为待收货
            if (batchSend) {
                row = orderModelMapper.updateOrderStatusByOrderNo(vo.getStoreId(), DictionaryConst.OrdersStatus.ORDERS_R_STATUS_DISPATCHED, orderNo);
                if (row < 1) {
                    logger.debug("订单{} 发货失败,状态修改失败", orderNo);
                    throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_FHSB, "发货失败");
                }
                //订单来源小程序并且使用小程序支付的话 全部发货完调用微信发货同步信息
                if (orderModel.getSource().toString().equals(DictionaryConst.StoreSource.LKT_LY_001)
                        && orderModel.getPay().equals(DictionaryConst.OrderPayType.ORDERPAYTYPE_MINI_WECHAT)){
                    publicExpressService.setWxAppUploadShippingInfo(vo, orderNo);
                }
            }
        } catch (LaiKeAPIException l) {
            throw l;
        } catch (Exception e) {
            logger.error("发货异常： ", e);
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_WLYC, "网络异常", "adminDelivery");
        }
    }


    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deliverySave(MainVo vo, Integer exId, String exNo, String orderDetailIds) throws LaiKeAPIException {
        try {
            // 请选择快递公司
            if (exId == null) {
                throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_QXZKDGS, "请选择快递公司");
            }
            if (org.apache.commons.lang3.StringUtils.isEmpty(exNo)) {
                throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_QSRKDDH, "请输入快递单号");
            }
            OrderDetailsModel orderDetailsModel = new OrderDetailsModel();
            orderDetailsModel.setExpress_id(exId);
            orderDetailsModel.setCourier_num(exNo);
            int count = orderDetailsModelMapper.selectCount(orderDetailsModel);
            if (count > 0) {
                throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_KDDHYCZ, "快递单号已存在");
            }

            publicOrderService.adminDelivery(vo, exId, exNo, orderDetailIds);
        } catch (LaiKeAPIException e) {
            throw e;
        } catch (Exception e) {
            logger.error("订单发货 异常", e);
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_WLYC, "网络异常", "orderPrint");
        }

    }


    @Override
    @Transactional(rollbackFor = Exception.class)
    public void saveEditOrder(EditOrderVo orderVo) throws LaiKeAPIException {
        try {
            int row;
            publiceService.getRedisUserCache(orderVo);
            if (org.apache.commons.lang3.StringUtils.isEmpty(orderVo.getOrderNo())) {
                throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_DDBJSB, "订单编辑失败");
            }
            //获取订单信息
            OrderModel orderModel = new OrderModel();
            orderModel.setStore_id(orderVo.getStoreId());
            orderModel.setsNo(orderVo.getOrderNo());
            orderModel = orderModelMapper.selectOne(orderModel);
            if (orderModel == null) {
                throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_DDBCZ, "订单不存在");
            }
            if (DictionaryConst.OrdersStatus.ORDERS_R_STATUS_CONSIGNMENT != orderModel.getStatus()
                    && DictionaryConst.OrdersStatus.ORDERS_R_STATUS_UNPAID != orderModel.getStatus()) {
                throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_DDYFHBNJXXG, "订单已发货,不能进行修改");
            }
            //是否是跨店铺
            String[] mchList = StringUtils.trim(orderModel.getMch_id(), com.laiketui.core.common.SplitUtils.DH).split(com.laiketui.core.common.SplitUtils.DH);
            boolean isManyMch = mchList.length > 1;

            OrderModel orderUpdate = new OrderModel();
            orderUpdate.setId(orderModel.getId());
            orderUpdate.setMobile(orderVo.getTel());
            orderUpdate.setSheng(orderVo.getShen());
            orderUpdate.setShi(orderVo.getShi());
            orderUpdate.setXian(orderVo.getXian());
            orderUpdate.setName(orderVo.getUserName());
            orderUpdate.setAddress(orderVo.getAddress());
            if (!isManyMch && StringUtils.isNotEmpty(orderVo.getRemarks())) {
                Map<String, String> remarksMap = new HashMap<>(1);
                remarksMap.put(mchList[0], orderVo.getRemarks());
                orderUpdate.setRemarks(JSON.toJSONString(remarksMap));
            }
            //修改订单信息
            if (DictionaryConst.OrdersStatus.ORDERS_R_STATUS_UNPAID == orderModel.getStatus()) {
                //订单状态（只能修改成待发货）
                if (DictionaryConst.OrdersStatus.ORDERS_R_STATUS_CONSIGNMENT == orderVo.getOrderStatus()) {
                    orderUpdate.setStatus(DictionaryConst.OrdersStatus.ORDERS_R_STATUS_CONSIGNMENT);
                    //修改订单明细状态
                    row = orderDetailsModelMapper.updateOrderDetailsStatus(orderVo.getStoreId(), orderVo.getOrderNo(), orderUpdate.getStatus());
                    if (row < 1) {
                        throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_XGSB, "修改失败");
                    }
                }
                //未付款可以修改订单金额、订单状态（只能修改成待发货）
                if (org.apache.commons.lang3.StringUtils.isNotEmpty(orderVo.getOrderAmt())) {
                    orderUpdate.setZ_price(new BigDecimal(orderVo.getOrderAmt()));
                    //修改订单金额后需要记录差额
                    BigDecimal priceDiff = orderModel.getZ_price().subtract(orderUpdate.getZ_price());
                    OrderDetailsModel orderDetailsModel = new OrderDetailsModel();
                    orderDetailsModel.setStore_id(orderVo.getStoreId());
                    orderDetailsModel.setR_sNo(orderVo.getOrderNo());
                    List<OrderDetailsModel> orderDetailsModelList = orderDetailsModelMapper.select(orderDetailsModel);
                    for (OrderDetailsModel orderDetails : orderDetailsModelList) {
                        //支付金额=优惠金额+运费
                        BigDecimal payMoney = orderDetails.getAfter_discount().add(orderDetails.getFreight());
                        //该单均摊差额 (优惠后金额+运费)/订单总金额*订单差额
                        BigDecimal updatePrice = payMoney.divide(orderModel.getZ_price(), 12, BigDecimal.ROUND_DOWN).multiply(priceDiff);
                        //重新计算优惠后金额 优惠后金额 - (优惠后金额/(优惠后金额+运费))*该单均摊金额
                        BigDecimal moneyTemp = orderDetails.getAfter_discount().divide(payMoney, 12, BigDecimal.ROUND_DOWN).multiply(updatePrice);
                        BigDecimal afterDiscount = orderDetails.getAfter_discount().subtract(moneyTemp).setScale(2, BigDecimal.ROUND_HALF_UP);
                        //重新计算运费金额 运费金额 - (运费金额/(优惠后金额+运费))*该单均摊金额
                        BigDecimal yunFeiPrice = orderDetails.getFreight().subtract(orderDetails.getFreight().divide(payMoney, 12, BigDecimal.ROUND_DOWN).multiply(updatePrice)).setScale(2, BigDecimal.ROUND_HALF_UP);

                        //修改订单明细金额
                        OrderDetailsModel orderDetailsUpdate = new OrderDetailsModel();
                        orderDetailsUpdate.setId(orderDetails.getId());
                        orderDetailsUpdate.setFreight(yunFeiPrice);
                        orderDetailsUpdate.setAfter_discount(afterDiscount);
                        row = orderDetailsModelMapper.updateByPrimaryKeySelective(orderDetailsUpdate);
                        if (row < 1) {
                            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_DDBJSB, "订单编辑失败");
                        }
                    }
                }
            }
            //修改订单基本信息
            row = orderModelMapper.updateByPrimaryKeySelective(orderUpdate);
            if (row < 1) {
                throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_XGSB, "修改失败");
            }

            publiceService.addAdminRecord(orderVo.getStoreId(), "修改了订单ID："+orderVo.getOrderNo()+" 的信息", AdminRecordModel.Type.UPDATE, orderVo.getAccessId());
        } catch (LaiKeAPIException l) {
            throw l;
        } catch (Exception e) {
            logger.error("订单编辑失败", e);
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_DDBJSB, "订单编辑失败", "saveEditOrder");
        }
    }


    @Override
    public Map<String, Object> deliveryView(AdminDeliveryVo adminDeliveryVo) throws LaiKeAPIException {
        Map<String, Object> retMap = Maps.newHashMap();
        try {
            int storeId = adminDeliveryVo.getStoreId();
            String sNo = adminDeliveryVo.getsNo();
            List<Map<String, Object>> ordersList = orderModelMapper.getDeleiveryOrders(storeId, sNo);
            // todo 未知变量
            int put = 1;
            List<Map<String, Object>> returnGoodsList = new ArrayList<>();
            for (Map<String, Object> orderInfo : ordersList) {
                orderInfo.put("imgurl", publiceService.getImgPath(MapUtils.getString(orderInfo, "imgurl"), storeId));
                int rstatus = MapUtils.getIntValue(orderInfo, "r_status");
                if (rstatus == 1) {
                    put = 0;
                }

                returnGoodsList.add(orderInfo);
            }
            retMap.put("express", searchExpress(null));
            retMap.put("id", sNo);
            retMap.put("put", put);
            retMap.put("goods", returnGoodsList);
            retMap.put("count", returnGoodsList.size());
            return retMap;
        } catch (LaiKeAPIException e) {
            throw e;
        } catch (Exception e) {
            logger.error("获取发货信息失败", e);
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_WLYC, "网络异常", "deliveryView");
        }
    }

    @Override
    public Map<String, Object> searchExpress(String express) throws LaiKeAPIException {
        Map<String, Object> resultMap = new HashMap<>(16);
        try {
            Map<String, Object> paramMap = new HashMap<>(16);
            paramMap.put("is_open", 1);
            paramMap.put("sort_sort", DataUtils.Sort.DESC.toString());
            if (org.apache.commons.lang3.StringUtils.isNotEmpty(express)) {
                paramMap.put("kuaidi_name", express);
            }

            int total = expressModelMapper.countDynamic(paramMap);
            List<Map<String, Object>> expressModelList = new ArrayList<>();
            if (total > 0) {
                expressModelList = expressModelMapper.selectDynamic(paramMap);
            }
            resultMap.put("total", total);
            resultMap.put("list", expressModelList);
            return resultMap;
        } catch (LaiKeAPIException e) {
            throw e;
        } catch (Exception e) {
            logger.error("获取快递信息失败：", e);
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_WLYC, "网络异常", "searchExpress");
        }
    }


    @Override
    public Map<String, Object> orderPcDetails(AdminOrderDetailVo adminOrderDetailVo) throws LaiKeAPIException {
        Map<String, Object> retMap = Maps.newConcurrentMap();
        try {
            int store_id = adminOrderDetailVo.getStoreId();
            String sNo = adminOrderDetailVo.getId();
            String orderType = adminOrderDetailVo.getOrderType();
            String type = adminOrderDetailVo.getType();
            boolean update_s = StringUtils.isEmpty(type);

            OrderConfigModal orderConfigModal = new OrderConfigModal();
            orderConfigModal.setStore_id(store_id);
            orderConfigModal = orderConfigModalMapper.selectOne(orderConfigModal);

            Date remind_time;
            if (orderConfigModal != null) {
                int remind = orderConfigModal.getRemind();
                if (remind == 0) {
                    remind_time = DateUtil.getAddDate(new Date(), 7);
                } else {
                    int remind_day = remind / 24;
                    int remind_hour = remind % 24;
                    remind_time = DateUtil.getAddDate(new Date(), remind_day);
                    remind_time = DateUtil.getAddDateBySecond(remind_time, remind_hour * 3600);
                }
            } else {
                remind_time = DateUtil.getAddDate(new Date(), 7);
            }

            //是否是多店铺订单
            boolean isManyMch = false;
            /*-----------进入订单详情把未读状态改成已读状态，已读状态的状态不变-------*/
            OrderModel orderModel = new OrderModel();
            orderModel.setStore_id(store_id);
            orderModel.setsNo(sNo);
            orderModel = orderModelMapper.selectOne(orderModel);
            // 订单总价
            BigDecimal pay_price = BigDecimal.ZERO;
            Map params = Maps.newConcurrentMap();
            if (orderModel == null) {
                throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_DDBCZ, "订单不存在");
            }
            if (orderModel.getMch_id().split(SplitUtils.DH).length > 2) {
                isManyMch = true;
            }
            type = orderModel.getOtype();
            pay_price = orderModel.getZ_price();
            String shopId = StringUtils.trim(orderModel.getMch_id(), SplitUtils.DH);
            Integer readd = orderModel.getReadd();
            if (readd == 0) {
                params.put("readd", 1);
                params.put("store_id", store_id);
                params.put("orderno", sNo);
                int delivery_status = orderModel.getDelivery_status();
                if (delivery_status == 1) {
                    params.put("remind", remind_time);
                }
                int row = orderModelMapper.updateByOrdernoDynamic(params);

                if (row < 1) {
                    logger.error("修改订单失败");
                }

                String order_status = "1,3,5";
                //可能存在多店铺情况
                String[] mchIds = shopId.split(SplitUtils.DH);
                for (String mchId : mchIds) {
                    messageLoggingModalMapper.updateMessLogInfo(store_id, Integer.parseInt(mchId), sNo, order_status);
                }
            }
            int status = orderModel.getStatus();
            if (status == DictionaryConst.OrdersStatus.ORDERS_R_STATUS_COMPLETE) {
                messageLoggingModalMapper.updateMessLogInfo(store_id, Integer.parseInt(shopId), sNo, "6");
            }
            if (status == DictionaryConst.OrdersStatus.ORDERS_R_STATUS_CLOSE && shopId.length() == 1) {
                messageLoggingModalMapper.updateMessLogInfo(store_id, Integer.parseInt(shopId), sNo, "4");
            }
            /*--------------------------------------------------------------------------*/
            //支付方式
            Map<String, String> paymentModelMap = publicPaymentConfigService.getPaymentMap();
            List<Map<String, Object>> adminOrderDetailsList = orderDetailsModelMapper.getAdminOrderDetailsInfo(sNo, store_id);
            int num = adminOrderDetailsList.size();
            Map<String, Object> data = new HashMap<>(16);
            // 满减金额
            BigDecimal reduce_price = BigDecimal.ZERO;
            // 优惠券金额
            BigDecimal coupon_price = BigDecimal.ZERO;
            // 平台优惠券金额
            BigDecimal preferential_amount = BigDecimal.ZERO;
            // 积分
            int allow = 0;
            BigDecimal yunfei = BigDecimal.ZERO;
            //
            List<String> courier_num_arr = new ArrayList<>();
            //快递字符串信息 xxx(xxx),...
            String kdStrFormat = "%s(%s),";
            StringBuilder kdStr = new StringBuilder();
            // 优惠金额
            BigDecimal yh_money = BigDecimal.ZERO;
            // 优惠类型
            String discount_type = "";
            // 优惠券ID
            Map<String, Object> orderDetailsData = adminOrderDetailsList.get(0);
            // 优惠券
            String coupon_id = DataUtils.getStringVal(orderDetailsData, "coupon_id", "0");
            // 满减活动ID
            Integer subtraction_id = DataUtils.getIntegerVal(orderDetailsData, "subtraction_id", 0);
            // 会员等级折扣
            BigDecimal grade_rate = DataUtils.getBigDecimalVal(orderDetailsData, "grade_rate", BigDecimal.ZERO);
            // 商品总价
            BigDecimal spz_price = DataUtils.getBigDecimalVal(orderDetailsData, "spz_price", BigDecimal.ZERO);
            // 总运费
            BigDecimal z_freight = DataUtils.getBigDecimalVal(orderDetailsData, "z_freight", BigDecimal.ZERO);
            // 订单类型
            String otype = DataUtils.getStringVal(orderDetailsData, "otype", "0");
            //$zifuchuan = trim(strrchr($coupon_id, ','),',');
            int zifuchuan = StringUtils.trim(coupon_id, SplitUtils.DH).indexOf(SplitUtils.DH);

            if (subtraction_id != 0) {
                discount_type = "满减";
            } else if (zifuchuan != 0) {
                discount_type = "优惠券";
            }

            //订单商品总价小计
            BigDecimal goodsPrice = new BigDecimal("0");
            // 会员优惠金额
            BigDecimal grade_rate_amount = BigDecimal.ZERO;
            List<String> express_ids = new ArrayList<String>();
            courier_num_arr = new ArrayList<>();
            data.put("fh", 0);
            int orderDetailsStatus = -1;
            for (Map<String, Object> orderDetailsMap : adminOrderDetailsList) {
                //订单详情id
                int orderDetailId = MapUtils.getIntValue(orderDetailsMap, "id");
                //商品图片
                String goodsImgUrl = MapUtils.getString(orderDetailsMap, "img");
                //商品规格id
                Integer attrId = MapUtils.getInteger(orderDetailsMap, "attrId");
                goodsImgUrl = publiceService.getImgPath(goodsImgUrl, store_id);
                orderDetailsMap.put("pic", goodsImgUrl);
                // 联系人
                data.put("user_name", MapUtils.getString(orderDetailsMap, "user_name"));
                // 联系人
                data.put("name", DataUtils.getStringVal(orderDetailsMap, "name", ""));
                String remarks = DataUtils.getStringVal(orderDetailsMap, "remarks", "");
                Map<String, String> remarksMap = new HashMap<>(16);
                //备注
                if (StringUtils.isNotEmpty(remarks)) {
                    // 订单备注
                    remarksMap = JSON.parseObject(remarks, new TypeReference<Map<String, String>>() {
                    });
                }
                StringBuilder remarksStr = new StringBuilder(SplitUtils.DH);
                for (String str : remarksMap.keySet()) {
                    remarksStr.append(remarksMap.get(str)).append(SplitUtils.DH);
                }
                data.put("remarks", StringUtils.trim(remarksStr.toString(), SplitUtils.DH));

                //订单类型
                data.put("orderTypeName", OrderDataUtils.getOrderType(MapUtils.getString(orderDetailsMap, "otype")));
                //支付时间
                String payTime = DateUtil.dateFormate(MapUtils.getString(orderDetailsMap, "pay_time"), GloabConst.TimePattern.YMDHMS);
                String addTime = DateUtil.dateFormate(MapUtils.getString(orderDetailsMap, "add_time"), GloabConst.TimePattern.YMDHMS);
                orderDetailsMap.put("pay_time", payTime);
                orderDetailsMap.put("add_time", addTime);
                if (StringUtils.isEmpty(payTime)) {
                    payTime = "";
                }
                //售后信息
                Map<String, Object> returnInfo = new HashMap<>(16);
                ReturnOrderModel returnOrderModel = returnOrderModelMapper.getReturnNewInfoByDetailId(orderDetailId);
                if (returnOrderModel != null) {
                    returnInfo.put("id", returnOrderModel.getId());
                    returnInfo.put("statusName", publicRefundService.getRefundStatus(store_id, returnOrderModel.getP_id()));
                }
                orderDetailsMap.put("returnInfo", returnInfo);

                //店铺信息
                String mchId = StringUtils.trim(MapUtils.getString(orderDetailsMap, "mch_id"), SplitUtils.DH);
                String[] mchIdList = mchId.split(SplitUtils.DH);
                for (String id : mchIdList) {
                    MchModel mchModel = new MchModel();
                    mchModel.setId(Integer.valueOf(id));
                    mchModel = mchModelMapper.selectOne(mchModel);
                    if (!Objects.isNull(mchModel)) {
                        orderDetailsMap.put("mchName", mchModel.getName());
                    }
                }

                data.put("pay_time", payTime);
                //来源
                data.put("source", MapUtils.getString(orderDetailsMap, "source"));
                //订单号
                data.put("sNo", MapUtils.getString(orderDetailsMap, "sNo"));
                // 联系电话
                data.put("oid", MapUtils.getString(orderDetailsMap, "oid"));
                // 联系电话
                data.put("mobile", MapUtils.getString(orderDetailsMap, "mobile"));
                //获取订单状态
                int orderStatus = MapUtils.getIntValue(orderDetailsMap, "status");
                orderDetailsMap.put("status", OrderDataUtils.getOrderStatus(orderStatus));
                //todo
                String grade_rate_tmp = DataUtils.getStringVal(orderDetailsMap, "grade_rate", "");
                if ("1.00".equalsIgnoreCase(grade_rate_tmp) || "0.00".equalsIgnoreCase(grade_rate_tmp) ||
                        "0".equalsIgnoreCase(grade_rate_tmp) || "1".equalsIgnoreCase(grade_rate_tmp)) {
                    data.put("grade_rate2", 1);
                    data.put("grade_rate", "-");
                } else {
                    data.put("grade_rate2", grade_rate_tmp);
                    BigDecimal grade = new BigDecimal(grade_rate_tmp).multiply(new BigDecimal("10"));
                    data.put("grade_rate", grade + "折");
                }

                BigDecimal pnum = DataUtils.getBigDecimalVal(orderDetailsMap, "num", BigDecimal.ZERO);
                BigDecimal p_price = DataUtils.getBigDecimalVal(orderDetailsMap, "p_price", BigDecimal.ONE);
                goodsPrice = goodsPrice.add(pnum.multiply(p_price));
                orderDetailsMap.put("spz_price", goodsPrice);
                //优惠金额
                yh_money = yh_money.add(pnum.multiply(p_price)).subtract(pnum.multiply(p_price).multiply(new BigDecimal(grade_rate_tmp)));

                String sheng = DataUtils.getStringVal(orderDetailsMap, "sheng", "");
                String shi = DataUtils.getStringVal(orderDetailsMap, "shi", "");
                String xian = DataUtils.getStringVal(orderDetailsMap, "xian", "");
                String address = DataUtils.getStringVal(orderDetailsMap, "address", "");

                BigDecimal zheKou = new BigDecimal("0");
                if (orderModel.getGrade_rate().compareTo(BigDecimal.ZERO) >= 0) {
                    zheKou = orderModel.getGrade_rate().multiply(new BigDecimal("10"));
                }
                data.put("grade_rate", zheKou);
                // 详细地址
                data.put("address", new StringBuilder().append(sheng).append(shi).append(xian).append(address));
                data.put("sheng", sheng);
                data.put("shi", shi);
                data.put("xian", xian);
                data.put("r_address", address);
                // 添加时间
                data.put("add_time", addTime);
                data.put("z_price", DataUtils.getBigDecimalVal(orderDetailsMap, "z_price", BigDecimal.ZERO));
                data.put("user_id", DataUtils.getStringVal(orderDetailsMap, "user_id", ""));
                // 发货时间
                String deliverTime = "";
                if (orderDetailsMap.containsKey("deliver_time")) {
                    deliverTime = MapUtils.getString(orderDetailsMap, "deliver_time");
                    if (StringUtils.isNotEmpty(deliverTime)) {
                        deliverTime = DateUtil.dateFormate(MapUtils.getString(orderDetailsMap, "deliver_time"), GloabConst.TimePattern.YMDHMS);
                    }
                }
                data.put("deliver_time", deliverTime);
                // 到货时间
                String arriveTime = "";
                if (orderDetailsMap.containsKey("arrive_time")) {
                    arriveTime = MapUtils.getString(orderDetailsMap, "arrive_time");
                }
                data.put("arrive_time", arriveTime);

                orderDetailsStatus = DataUtils.getIntegerVal(orderDetailsMap, "r_status", -1);
                // 订单详情状态
                data.put("r_status", orderDetailsStatus);
                data.put("status01", orderDetailsStatus);
                data.put("gstatus", orderDetailsStatus);
                // 订单类型
                data.put("otype", DataUtils.getStringVal(orderDetailsMap, "otype", ""));
                // 退货原因
                String contentReturn = "";
                if (orderDetailsMap.containsKey("content")) {
                    contentReturn = MapUtils.getString(orderDetailsMap, "content");
                }
                data.put("content", contentReturn);
                // 快递公司id
                String express_id = DataUtils.getStringVal(orderDetailsMap, "express_id", "");
                //
                data.put("express_id", express_id);
                if (!StringUtils.isEmpty(express_id)) {
                    if (!express_ids.contains(express_id)) {
                        express_ids.add(express_id);
                    }
                }

                String courier_num = DataUtils.getStringVal(orderDetailsMap, "courier_num", "");
                String kuaidi_name = DataUtils.getStringVal(orderDetailsMap, "kuaidi_name", "");
                if (StringUtils.isNotEmpty(courier_num)) {
                    List<Map<String, String>> cnsList = new ArrayList<>();
                    if (!courier_num_arr.contains(courier_num)) {
                        Map<String, String> tmpData = Maps.newConcurrentMap();
                        tmpData.put("num", DataUtils.getStringVal(orderDetailsMap, "num", ""));
                        tmpData.put("kuaidi_name", kuaidi_name);
                        cnsList.add(tmpData);
                        data.put("courier_num", cnsList);
                        courier_num_arr.add(courier_num);

                        kdStr.append(String.format(kdStrFormat, kuaidi_name, courier_num));
                    }
                }

                if (StringUtils.isNotEmpty(kuaidi_name)) {
                    data.put("fh", 1);
                }

                // 满减金额
                reduce_price = DataUtils.getBigDecimalVal(orderDetailsMap, "reduce_price", BigDecimal.ZERO);
                // 优惠券金额 优惠金额记录的是 店铺优惠卷+平台优惠卷金额
                coupon_price = DataUtils.getBigDecimalVal(orderDetailsMap, "coupon_price", BigDecimal.ZERO);
                // 平台优惠券金额
                preferential_amount = DataUtils.getBigDecimalVal(orderDetailsMap, "preferential_amount", BigDecimal.ZERO);
                if (preferential_amount.compareTo(BigDecimal.ZERO) > 0) {
                    //计算店铺优惠金额
                    coupon_price = coupon_price.subtract(preferential_amount);
                }
                // 积分
                allow = DataUtils.getIntegerVal(orderDetailsMap, "allow", 0);
                String pay = DataUtils.getStringVal(orderDetailsMap, "pay", "");
                String paytype = "";
                if (paymentModelMap.containsKey(pay)) {
                    paytype = paymentModelMap.get(pay);
                }
                // 支付方式
                data.put("paytype", paytype);
                data.put("lottery_status", 7);
                data.put("id", sNo);
                // 微信支付交易号
                data.put("trade_no", DataUtils.getStringVal(orderDetailsMap, "trade_no", ""));
                BigDecimal freight = DataUtils.getBigDecimalVal(orderDetailsMap, "", BigDecimal.ZERO);
                yunfei = yunfei.add(freight);
                data.put("paytype", paytype);
                // 根据产品id,查询产品主图
                ProductListModel productListModel = new ProductListModel();
                productListModel.setId(DataUtils.getIntegerVal(orderDetailsMap, "p_id", 0));
                //如果是其它插件订单则获取商品id
                if (!DictionaryConst.OrdersType.ORDERS_HEADER_GM.equals(orderModel.getOtype())) {
                    ConfiGureModel confiGureModel = confiGureModelMapper.selectByPrimaryKey(attrId);
                    if (confiGureModel == null) {
                        throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_SPSXBCZ, "商品属性不存在");
                    }
                    productListModel.setId(confiGureModel.getPid());
                    //积分商品使用积分商品库存替换商品库存
                    if (otype.equals(DictionaryConst.OrdersType.ORDERS_HEADER_IN)){
                        orderDetailsMap.put("total_num", integralGoodsModelMapper.selectAttrNumByAttrId(store_id, attrId));
                    }
                }
            }
            yh_money = yh_money.add(coupon_price).add(reduce_price);
            // 运费
            data.put("yunfei", yunfei);
            data.put("express_name", "");
            data.put("z_freight", orderModel.getOld_freight()== null ?  z_freight : orderModel.getOld_freight());
            if (!CollectionUtils.isEmpty(express_ids)) {
                for (String expressId : express_ids) {
                    // 根据快递公司id,查询快递公司表信息
                    ExpressModel expressModel = new ExpressModel();
                    expressModel.setId(Integer.parseInt(expressId));
                    expressModel = expressModelMapper.selectOne(expressModel);
                    String tmpKuaidiName = expressModel.getKuaidi_name();
                    if (StringUtils.isNotEmpty(tmpKuaidiName)) {
                        // 快递公司名称
                        data.put("express_name", data.get("express_name") + tmpKuaidiName + SplitUtils.DH);
                    }
                }
            }

            getOrderStatus(data, orderDetailsStatus);
            if ("modify".equalsIgnoreCase(orderType)) {
                //订单状态 为待收货可以编辑订单发货号
                if (orderDetailsStatus == DictionaryConst.OrdersStatus.ORDERS_R_STATUS_DISPATCHED) {
                    List<Map<String, String>> cnsList = DataUtils.cast(data.get("courier_num"));
                    if (!CollectionUtils.isEmpty(cnsList)) {
                        if (cnsList.size() == 1) {
                            data.put("courier_num", cnsList.get(0).get("num"));
                        }
                    }
                }
            }

            //订单状态
            List<String> orderStatusCnName = ImmutableList.of("待付款", "待发货", "待收货", "订单完成", "订单关闭");
            retMap.put("sdata", orderStatusCnName);
            retMap.put("yh_money", yh_money);
            //满减赠品
            retMap.put("zp_res", new ArrayList<>());
            retMap.put("update_s", update_s);
            retMap.put("data", data);
            retMap.put("detail", adminOrderDetailsList);
            retMap.put("reduce_price", reduce_price);
            retMap.put("coupon_price", coupon_price);
            retMap.put("preferential_amount", preferential_amount);
            retMap.put("grade_rate_amount", grade_rate_amount);
            retMap.put("allow", allow);
            retMap.put("num", num);
            retMap.put("discount_type", discount_type);
            retMap.put("pay_price", orderModel.getOld_total() == null ?  pay_price : orderModel.getOld_total());
            retMap.put("z_freight", orderModel.getOld_freight()== null ?  z_freight : orderModel.getOld_freight());
            retMap.put("grade_rate", grade_rate);
            //商品总价小计
            retMap.put("spz_price", goodsPrice);
            //快递
            retMap.put("expressStr", StringUtils.trim(kdStr.toString(), SplitUtils.DH));
            //订单备注
            String remark = "";
            remark = orderModel.getRemark() == null ? "" : orderModel.getRemark();
            retMap.put("remark", remark);
            //是否多店铺订单
            retMap.put("isManyMch", isManyMch);
            //退款状态
            retMap.put("returnStatus", publicRefundService.getRefundStatus(store_id, sNo));
        } catch (Exception e) {
            logger.error("获取订单详情 异常", e);
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_HQDDXQSB, "获取订单详情失败", "orderPcDetails");
        }
        return retMap;
    }

    /**
     * 后台获取订单状态
     *
     * @param orderInfo
     * @param statusInt
     */
    private void getOrderStatus(Map<String, Object> orderInfo, int statusInt) {
        switch (statusInt) {
            case DictionaryConst.OrdersStatus.ORDERS_R_STATUS_UNPAID:
                orderInfo.put("status", "待付款");
                orderInfo.put("bgcolor", "#f5b1aa");
                break;
            case DictionaryConst.OrdersStatus.ORDERS_R_STATUS_CONSIGNMENT:
                orderInfo.put("status", "待发货");
                orderInfo.put("bgcolor", "#f09199");
                break;
            case DictionaryConst.OrdersStatus.ORDERS_R_STATUS_DISPATCHED:
                orderInfo.put("status", "待收货");
                orderInfo.put("bgcolor", "#f19072");
                break;
            case DictionaryConst.OrdersStatus.ORDERS_R_STATUS_COMPLETE:
                orderInfo.put("status", "订单完成");
                orderInfo.put("bgcolor", "#f7b977");
                break;
            case DictionaryConst.OrdersStatus.ORDERS_R_STATUS_CLOSE:
                orderInfo.put("status", "订单关闭");
                orderInfo.put("bgcolor", "#ffbd8b");
                break;
        }
    }

    @Override
    public Map<String, Object> getLogistics(String orderNo) throws LaiKeAPIException {
        Map<String, Object> resultMap = new HashMap<>(16);
        try {
            List<Object> resultList = new ArrayList<>(16);
            //物流信息集
            List<Object> dataList = new ArrayList<>();
            //商品信息快递单号分组
            Map<String, Map<String, Object>> goodsGroupMap = new HashMap<>(16);

            //获取订单信息
            OrderModel orderModel = new OrderModel();
            orderModel.setsNo(orderNo);
            orderModel = orderModelMapper.selectOne(orderModel);
            if (orderModel != null) {
                //收货人号码 ->顺丰速运、顺丰快运必填
                String mobile = orderModel.getMobile();
                //物流去重,如果多个商品统一发货则只显示一个物流动态
                Set<String> wuLiuIds = new HashSet<>();
                //商品分组
                Map<String, List<Map<String, Object>>> goodsGroupList = new HashMap<>(16);

                //快递查询付费接口开关
                boolean isOpen = false;
                //获取配置信息
                ConfigModel configModel = new ConfigModel();
                configModel.setStore_id(orderModel.getStore_id());
                configModel = configModelMapper.selectOne(configModel);
                if (configModel != null && StringUtils.isNotEmpty(configModel.getExpress_address())) {
                    if (configModel.getIs_express() == 1) {
                        isOpen = true;
                    }
                }

                OrderDetailsModel orderDetailsModel = new OrderDetailsModel();
                orderDetailsModel.setR_sNo(orderNo);
                List<OrderDetailsModel> orderDetailsModelList = orderDetailsModelMapper.select(orderDetailsModel);
                for (OrderDetailsModel orderDetails : orderDetailsModelList) {
                    Map<String, Object> resultMapTemp = new HashMap<>(16);
                    Map<String, Object> goodsMap = new HashMap<>(16);
                    //快递公司id
                    Integer expressId = StringUtils.stringParseInt(orderDetails.getExpress_id() + "");
                    //快递单号
                    String courierNum = orderDetails.getCourier_num();
                    //快递名称
                    String kdName = "";
                    //快递公司代号
                    String kdCode = "";
                    String wuLiuKey = expressId + courierNum;
                    if (wuLiuIds.contains(wuLiuKey)) {
                        continue;
                    }

                    //获取快递公司代码
                    if (expressId != null && expressId > 0) {
                        ExpressModel expressModel = expressModelMapper.selectByPrimaryKey(expressId);
                        if (expressModel == null) {
                            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_WLGSBCZ, "物流公司不存在");
                        }
                        kdName = expressModel.getKuaidi_name();
                        kdCode = expressModel.getType();
                        String url;
                        String resultJson;
                        if (isOpen) {
                            url = configModel.getExpress_address();
                            Map<String, Object> parma = new HashMap<>(16);
                            parma.put("com", kdCode);
                            parma.put("num", courierNum);
                            parma.put("phone", mobile);
                            parma.put("from", "");
                            parma.put("to", "");
                            parma.put("resultv2", "1");
                            //请求参数
                            String param = JSON.toJSONString(parma);
                            //签名
                            String sign = Md5Util.MD5endoce(param + configModel.getExpress_key() + configModel.getExpress_number());
                            if (sign == null) {
                                throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_SJCW, "数据错误");
                            }
                            url += "?param=" + param + "&sign=" + sign.toUpperCase() + "&customer=" + configModel.getExpress_number();

                            resultJson = HttpUtils.post(url);
                        } else {
                            url = String.format(GloabConst.OtherUrl.API_KUAIDI100_URL, kdCode, courierNum);
                            resultJson = HttpUtils.get(url);
                        }
                        logger.debug("正在获取编号{}的物流信息 url{}", courierNum, url);

                        JSONObject obj = JSONObject.parseObject(resultJson);
                        if (obj.containsKey("data")) {
                            dataList = DataUtils.cast(obj.get("data"));
                        } else {
                            dataList = new ArrayList<>();
                        }
                        //获取商品信息
                        ConfiGureModel confiGureModel = confiGureModelMapper.selectByPrimaryKey(orderDetails.getSid());
                        goodsMap.put("img", publiceService.getImgPath(confiGureModel.getImg(), orderDetails.getStore_id()));
                        goodsMap.put("num", orderDetails.getNum());
                    }
                    //分组
                    if (goodsGroupMap.containsKey(courierNum)) {
                        //获取同单物流信息
                        resultMapTemp = goodsGroupMap.get(courierNum);
                        List<Map<String, Object>> goodsListTemp = goodsGroupList.get(courierNum);
                        resultMapTemp.put("pro_list", goodsListTemp);
                    } else {
                        //商品信息根据物流单分组
                        List<Map<String, Object>> goodsListTemp = new ArrayList<>();
                        if (goodsGroupList.containsKey(courierNum)) {
                            goodsListTemp.addAll(goodsGroupList.get(courierNum));
                        } else {
                            goodsListTemp.add(goodsMap);
                            goodsGroupList.put(courierNum, goodsListTemp);
                        }
                        //构造数据结构
                        resultMapTemp.put("list", dataList);
                        resultMapTemp.put("pro_list", goodsListTemp);
                        resultMapTemp.put("kuaidi_name", kdName);
                        resultMapTemp.put("courier_num", courierNum);
                        resultMapTemp.put("type", kdCode);
                        //是否为售后物流 1=订单物流 2=售后物流
                        resultMapTemp.put("shop_type", 1);
                        goodsGroupMap.put(courierNum, resultMapTemp);
                    }
                    wuLiuIds.add(wuLiuKey);
                    resultList.add(resultMapTemp);
                }
            } else if (StringUtils.isInteger(orderNo)) {
                //售后物流
                ReturnOrderModel returnOrderModel = returnOrderModelMapper.selectByPrimaryKey(orderNo);
                if (returnOrderModel != null) {
                    ReturnGoodsModel returnGoodsModel = new ReturnGoodsModel();
                    returnGoodsModel.setStore_id(returnOrderModel.getStore_id());
                    returnGoodsModel.setOid(String.valueOf(returnOrderModel.getP_id()));
                    List<ReturnGoodsModel> list = returnGoodsModelMapper.select(returnGoodsModel);
                    for (ReturnGoodsModel returnGoods : list) {
                        Map<String, Object> resultMapTemp;
                        //快递公司id
                        String express = returnGoods.getExpress();
                        //快递单号
                        String courierNum = returnGoods.getExpress_num();
                        //快递名称
                        String kdName = "";
                        //快递公司代号
                        String kdCode = "";

                        //获取订单明细
                        OrderDetailsModel orderDetailsModel = new OrderDetailsModel();
                        orderDetailsModel.setR_sNo(orderNo);
                        orderDetailsModel.setId(Integer.parseInt(returnGoods.getOid()));
                        OrderDetailsModel orderDetails = orderDetailsModelMapper.selectOne(orderDetailsModel);
                        //获取商品信息
                        ConfiGureModel confiGureModel = confiGureModelMapper.selectByPrimaryKey(orderDetails.getSid());
                        //获取快递公司代码
                        if (express != null) {
                            ExpressModel expressModel = new ExpressModel();
                            expressModel.setKuaidi_name(express);
                            expressModel.setRecycle(DictionaryConst.ProductRecycle.NOT_STATUS);
                            expressModel = expressModelMapper.selectOne(expressModel);
                            kdName = expressModel.getKuaidi_name();
                            kdCode = expressModel.getType();
                            String url = String.format(GloabConst.OtherUrl.API_KUAIDI100_URL, kdCode, courierNum);
                            logger.debug("正在获取编号{}的物流信息 url{}", courierNum, url);
                            String resultJson = HttpUtils.get(url);
                            JSONObject obj = JSONObject.parseObject(resultJson);
                            if (obj.containsKey("data")) {
                                dataList = DataUtils.cast(obj.get("data"));
                            } else {
                                dataList = new ArrayList<>();
                            }
                        }
                        //分组
                        if (goodsGroupMap.containsKey(courierNum)) {
                            resultMapTemp = goodsGroupMap.get(courierNum);
                        } else {
                            //构造数据结构
                            Map<String, Object> tempMap = new HashMap<>(16);
                            tempMap.put("list", dataList);
                            Map<String, Object> goodsMap = new HashMap<>(16);
                            //商品信息
                            List<Map<String, Object>> goodsInfo = new ArrayList<>();
                            goodsMap.put("img", publiceService.getImgPath(confiGureModel.getImg(), orderDetails.getStore_id()));
                            goodsMap.put("num", orderDetails.getNum());
                            goodsInfo.add(goodsMap);

                            tempMap.put("pro_list", goodsInfo);
                            tempMap.put("kuaidi_name", kdName);
                            tempMap.put("courier_num", courierNum);
                            tempMap.put("type", kdCode);
                            //是否为售后物流 1=订单物流 2=售后物流
                            tempMap.put("shop_type", 2);
                            resultMapTemp = tempMap;
                            goodsGroupMap.put(courierNum, resultMapTemp);
                        }
                        resultList.add(resultMapTemp);
                    }
                }
            } else {
                throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_DDBCZ, "订单不存在", "logistics");
            }

            resultMap.put("list", resultList);
            return resultMap;
        } catch (LaiKeAPIException l) {
            throw l;
        } catch (Exception e) {
            logger.error("获取物流信息 异常:", e);
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_HQWLXXYC, "获取物流信息 异常", "getLogistics");
        }
    }

    @Override
    public Map<String, Object> orderDetailsInfo(AdminOrderDetailVo orderVo) {
        try {
            String sNo = orderVo.getsNo();
            orderVo.setId(sNo);
            orderVo.setsNo(sNo);
            orderVo.setOrderType("see");
            return publicOrderService.orderPcDetails(orderVo);
        } catch (LaiKeAPIException l) {
            throw l;
        } catch (Exception e) {
            logger.error("订单详情异常", e);
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.BUSY_NETWORK, "订单编辑失败", "orderDetailsInfo");
        }
    }


    @Override
    public Map<String, Object> editOrderView(OrderModifyVo orderVo) throws LaiKeAPIException {
        Map<String, Object> retMap = Maps.newConcurrentMap();
        try {
            // 订单id sno
            String sNo = orderVo.getsNo();
            AdminOrderDetailVo adminOrderDetailVo = new AdminOrderDetailVo();
            adminOrderDetailVo.setId(sNo);
            adminOrderDetailVo.setsNo(sNo);
            adminOrderDetailVo.setOrderType("modify");
            adminOrderDetailVo.setType(orderVo.getType());
            adminOrderDetailVo.setStoreId(orderVo.getStoreId());
            Map<String, Object> adminOrderDetailsMap = publicOrderService.orderPcDetails(adminOrderDetailVo);
            List<ExpressModel> expressModels = publicExpressService.getExpressInfo();
            adminOrderDetailsMap.put("express", expressModels);
            retMap.putAll(adminOrderDetailsMap);
        } catch (LaiKeAPIException e) {
            throw e;
        } catch (Exception e) {
            logger.error("订单编辑失败", e);
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.BUSY_NETWORK, "订单详情获取失败", "editOrderView");
        }
        return retMap;
    }

    @Override
    public Map<String, Object> kuaidishow(MainVo vo, String orderNo) throws LaiKeAPIException {
        Map<String, Object> resultMap = new HashMap<>(16);
        try {
            publiceService.getRedisUserCache(vo);
            resultMap = publicOrderService.getLogistics(orderNo);
        } catch (LaiKeAPIException l) {
            throw l;
        } catch (Exception e) {
            logger.error("获取订单物流信息 异常", e);
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.BUSY_NETWORK, "网络异常", "kuaidishow");
        }
        return resultMap;
    }

    @Override
    public Map<String, Object> orderList(OrderVo vo) throws LaiKeAPIException {
        Map<String, Object> resultMap = new HashMap<>(16);
        try {
            User user = publiceService.getRedisUserCache(vo);

            Map<String, Object> parmaMap = new HashMap<>(16);
            parmaMap.put("storeId", vo.getStoreId());
            parmaMap.put("userId", user.getUser_id());
            parmaMap.put("orderType", vo.getQueryOrderType());
            parmaMap.put("status", "notClose");
            parmaMap.put("pageStart", vo.getPageNo());
            parmaMap.put("pageEnd", vo.getPageSize());
            parmaMap.put("otype", DictionaryConst.OrdersType.ORDERS_HEADER_IN);
            List<Map<String, Object>> orderList = orderModelMapper.selectDynamic(parmaMap);
            for (Map<String, Object> orderInfo : orderList) {
                //总运费
                BigDecimal totalYunFei = new BigDecimal("0");
                //商品总数量
                BigDecimal totalNeedNum = new BigDecimal("0");
                //订单号
                String orderno = orderInfo.get("sNo").toString();
                //店铺id
                int mchId = 0;
                // 店铺 名称
                String mchName = "";
                // 店铺logo
                String logoUrl = "";

                //店铺信息处理
                String mchIdStr = orderInfo.get("mch_id") + "";
                if (!StringUtils.isEmpty(mchIdStr)) {
                    mchId = Integer.parseInt(StringUtils.trim(mchIdStr, com.laiketui.core.common.SplitUtils.DH));
                    //获取店铺信息
                    MchModel mchModel = mchModelMapper.selectByPrimaryKey(mchId);
                    mchName = mchModel.getName();
                    logoUrl = publiceService.getImgPath(mchModel.getLogo(), vo.getStoreId());
                }
                orderInfo.put("shop_id", mchId);
                orderInfo.put("shop_name", mchName);
                orderInfo.put("shop_logo", logoUrl);

                //获取订单明细
                OrderDetailsModel orderDetailsModel = new OrderDetailsModel();
                orderDetailsModel.setStore_id(vo.getStoreId());
                orderDetailsModel.setR_sNo(orderno);
                List<Map<String, Object>> orderDetailsModelList = orderDetailsModelMapper.getOrderDetailNotClose(vo.getStoreId(), orderno);
                for (Map<String, Object> orderDetails : orderDetailsModelList) {
                    //统计运费
                    totalYunFei = totalYunFei.add(new BigDecimal(orderDetails.get("freight").toString()));
                    totalNeedNum = totalNeedNum.add(new BigDecimal(orderDetails.get("num").toString()));
                    int attrId = Integer.parseInt(orderDetails.get("sid").toString());
                    ConfiGureModel confiGureModel = confiGureModelMapper.selectByPrimaryKey(attrId);
                    if (confiGureModel == null) {
                        throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_SJCW, "数据错误");
                    }
                    int goodsId = confiGureModel.getPid();
                    //获取商品信息
                    ProductListModel productListModel = productListModelMapper.selectByPrimaryKey(goodsId);
                    orderDetails.put("pro_id", goodsId);
                    orderDetails.put("imgurl", publiceService.getImgPath(productListModel.getImgurl(), vo.getStoreId()));
                }
                orderInfo.put("refund", true);
                orderInfo.put("list", orderDetailsModelList);
                orderInfo.put("z_freight", totalYunFei);
                orderInfo.put("sum", totalNeedNum);
            }
            resultMap.put("order", orderList);
        } catch (LaiKeAPIException l) {
            throw l;
        } catch (Exception e) {
            logger.error("积分订单列表 异常", e);
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_WLYC, "网络异常", "orderList");
        }
        return resultMap;
    }

    @Override
    public Map<String, Object> okOrder(int storeId, String accessId, String orderno, Integer rType) {
        Map<String, Object> ret = Maps.newHashMap();
        try {
            MainVo vo = new MainVo();
            vo.setStoreId(storeId);
            vo.setAccessId(accessId);
            ret = this.okOrder(vo, GloabConst.RedisHeaderKey.LOGIN_ACCESS_TOKEN, orderno, rType);
        } catch (LaiKeAPIException l) {
            logger.error("确认收货 失败", l);
            throw l;
        } catch (Exception e) {
            logger.error("确认收货 异常", e);
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_YWYC, "业务异常", "okOrder");
        }

        return ret;
    }


    @Override
    public Map<String, Object> okOrder(MainVo vo, String tokenKey, String orderNo, Integer rType) throws LaiKeAPIException {
        Map<String, Object> ret = new HashMap<>(16);
        try {
            // 根据授权id,查询用户id
            if (StringUtils.isEmpty(vo.getAccessId())) {
                throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_CSCW, "参数错误");
            }
            User user = RedisDataTool.getRedisUserCache(vo.getAccessId(), redisUtil, tokenKey, true);
            // 获取信息
            OrderModel orderModel = new OrderModel();
            orderModel.setsNo(orderNo);
            orderModel = orderModelMapper.selectOne(orderModel);
            if (orderModel == null) {
                logger.error("订单不存在！");
                throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_QRSHSB, "确认收货失败", "okOrder");
            }
            //自提订单确认售后不能走这里
            if (orderModel.getSelf_lifting().equals(1)) {
                logger.error("自提订单不能点击确认收货,只能走校验码！");
                throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_QRSHSB, "确认收货失败", "okOrder");
            }

            // 售后商品回寄收货
            if (rType != null && rType.equals(DictionaryConst.ReturnOrderStatus.RETURNORDERSTATUS_AGREE_REBACK_GOODS)) {
                //查询订单信息
                ret.put("code", 200);
                int row = orderDetailsModelMapper.updateOkOrderDetails(vo.getStoreId(), orderModel.getId());
                if (row < 1) {
                    logger.error("确认收货失败！");
                    throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_QRSHSB, "确认收货失败", "okOrder");
                } else {
                    return ret;
                }
            }
            String userId = user.getUser_id();
            String sNo = orderModel.getsNo();
            //积分
            Integer allow = orderModel.getAllow();
            allow = allow == null ? 0 : allow;
            //订单金额
            BigDecimal zPrice = orderModel.getZ_price();
            //最终可到店铺账上的金额
            BigDecimal realMoney = BigDecimal.ZERO;
            OrderDetailsModel orderDetails = new OrderDetailsModel();
            orderDetails.setStore_id(vo.getStoreId());
            orderDetails.setUser_id(userId);
            orderDetails.setR_sNo(orderModel.getsNo());
            List<OrderDetailsModel> orderDetailsModels = orderDetailsModelMapper.select(orderDetails);
            if (CollectionUtils.isEmpty(orderDetailsModels)) {
                throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_CSCW, "参数错误", "okOrder");
            }

            Map<String, Object> param = new HashMap<>(16);
            for (OrderDetailsModel orderDetailsModel : orderDetailsModels) {
                int orderDetailsId = orderDetailsModel.getId();
                Integer rStatus = orderDetailsModel.getR_status();
                // 待收货
                if (rStatus == OrderModel.ORDER_UNRECEIVE) {
                    //计算实际可到账的金额 如果是积分,优惠金额则是积分
                    BigDecimal afterDiscount = orderDetailsModel.getAfter_discount();
                    if (orderModel.getOtype().equals(DictionaryConst.OrdersType.ORDERS_HEADER_IN)) {
                        afterDiscount = BigDecimal.ZERO;
                    }
                    realMoney = realMoney.add(afterDiscount).add(orderDetailsModel.getFreight());
                    param.put("r_status", OrderModel.ORDER_FINISH);
                    param.put("arrive_time", new Date());
                    param.put("storeId", vo.getStoreId());
                    param.put("detailId", orderDetailsId);
                    param.put("orderno", sNo);
                    int row = orderDetailsModelMapper.updateByOrdernoDynamic(param);
                    if (row < 0) {
                        throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_QRSHSB, "确认收货失败", "okOrder");
                    }
                }
            }

            //订单完成
            int row = orderModelMapper.updateOrderStatus(vo.getStoreId(), sNo, userId, OrderModel.ORDER_FINISH);
            if (row < 0) {
                throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_QRSHSB, "确认收货失败", "okOrder");
            }

            // 已收货
            int mchId = Integer.parseInt(StringUtils.trim(orderModel.getMch_id(), com.laiketui.core.common.SplitUtils.DH));

            //通知后台消息
            MessageLoggingModal messageLoggingSave = new MessageLoggingModal();
            messageLoggingSave.setStore_id(vo.getStoreId());
            messageLoggingSave.setMch_id(mchId);
            messageLoggingSave.setType(MessageLoggingModal.Type.TYPE_ORDER_OK_GOODS);
            messageLoggingSave.setTo_url(OrderDataUtils.getOrderRoute(orderModel.getOtype(), 0));
            messageLoggingSave.setParameter(orderModel.getId() + "");
            messageLoggingSave.setContent(String.format("订单%s，用户已确定收货！", orderModel.getsNo()));
            messageLoggingSave.setAdd_date(new Date());
            messageLoggingModalMapper.insertSelective(messageLoggingSave);

            //确认收货到店铺账上的金额不能是订单金额  一个订单多个商品,一个退款(少退),其余的确认收货,少退的部分还在订单金额里面,但实际上这笔钱已经结算到店铺可提现金额里面了
            publicMchService.clientConfirmReceipt(vo.getStoreId(), mchId, sNo, realMoney, new BigDecimal(allow));
            ret.put("code", 200);
        } catch (LaiKeAPIException l) {
            logger.error("确认收货 失败", l);
            throw l;
        } catch (Exception e) {
            logger.error("确认收货 异常", e);
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_YWYC, "业务异常", "okOrder");
        }
        return ret;
    }

    @Override
    public Map<String, Object> getOrderConfig(int storeId, String oType) throws LaiKeAPIException {
        try {
            return getOrderConfig(storeId, null, oType);
        } catch (Exception e) {
            logger.error("根据订单类型获取订单配置 异常:", e);
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_WLYC, "网络异常");
        }
    }


    @Override
    public Map<String, Object> getOrderConfig(int storeId, Integer mchId, String oType) throws LaiKeAPIException {
        Map<String, Object> resultMap = new HashMap<>(16);
        try {
            return getOrderConfig(storeId, mchId, oType, true);
        } catch (Exception e) {
            logger.error("根据订单类型获取订单配置 异常:", e);
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_WLYC, "网络异常");
        }
    }

    @Override
    public Map<String, Object> getOrderConfig(int storeId, Integer mchId, String oType, boolean isOpenConfig) throws LaiKeAPIException {
        Map<String, Object> resultMap = new HashMap<>(16);
        try {
            //默认获取自营店id
            Integer storeMchId = customerModelMapper.getStoreMchId(storeId);
            //自动收货时间
            int autoTeGood =DateUtil.dateConversion(7, DateUtil.TimeType.DAY);
            //是否需要结算,如果是false则不走结算
            boolean isSettlement = true;
            //订单失效
            int orderFailureDay = DateUtil.dateConversion(1, DateUtil.TimeType.DAY);
            //自动评价内容
            String autoCommentContent = "评价方未及时评价，系统自动默认好评";
            //发货提醒限制
            int remind = DateUtil.dateConversion(1, DateUtil.TimeType.TIME);
            //定时好评
            int commentDay = DateUtil.dateConversion(7, DateUtil.TimeType.DAY);
            //订单售后时间
            int orderAfter = DateUtil.dateConversion(7, DateUtil.TimeType.DAY);
            Map<String, Object> paramMap = new HashMap<>(1);
            switch (oType.toUpperCase()) {
                //获取订单配置信息 普通订单设置单位是天 插件都是秒
                case DictionaryConst.OrdersType.ORDERS_HEADER_GM:
                case DictionaryConst.OrdersType.ORDERS_HEADER_FX:
                    OrderConfigModal orderConfigModal = new OrderConfigModal();
                    orderConfigModal.setStore_id(storeId);
                    orderConfigModal = orderConfigModalMapper.selectOne(orderConfigModal);
                    if (orderConfigModal != null) {
                        autoTeGood = DateUtil.dateConversion(orderConfigModal.getAuto_the_goods(), DateUtil.TimeType.DAY);
                        orderFailureDay = DateUtil.dateConversion(orderConfigModal.getOrder_failure(), DateUtil.TimeType.TIME);
                        remind = DateUtil.dateConversion(orderConfigModal.getRemind(), DateUtil.TimeType.TIME);
                        commentDay = DateUtil.dateConversion(orderConfigModal.getAuto_good_comment_day(), DateUtil.TimeType.DAY);
                        orderAfter = DateUtil.dateConversion(orderConfigModal.getOrder_after(), DateUtil.TimeType.DAY);
                        if (StringUtils.isNotEmpty(orderConfigModal.getAuto_good_comment_content())) {
                            autoCommentContent = orderConfigModal.getAuto_good_comment_content();
                        }
                    }
                    break;
                case DictionaryConst.OrdersType.ORDERS_HEADER_MS:
                    SecondsConfigModel secondsConfigModel = new SecondsConfigModel();
                    secondsConfigModel.setStore_id(storeId);
                    secondsConfigModel.setMch_id(storeMchId);
                    secondsConfigModel = secondsConfigModelMapper.selectOne(secondsConfigModel);
                    if (secondsConfigModel == null || secondsConfigModel.getIs_open() == DictionaryConst.WhetherMaven.WHETHER_NO) {
                        logger.debug("【秒杀】插件未开启/未配置");
                        return null;
                    }
                    autoTeGood = secondsConfigModel.getAuto_the_goods();
                    orderFailureDay = secondsConfigModel.getOrder_failure();
                    remind = secondsConfigModel.getDeliver_remind();
                    commentDay = secondsConfigModel.getAuto_good_comment_day();
                    //秒杀售后默认15天...
                    orderAfter = secondsConfigModel.getOrder_after();
                    break;
                case DictionaryConst.OrdersType.ORDERS_HEADER_IN:
                    IntegralConfigModel integralConfigModel = new IntegralConfigModel();
                    integralConfigModel.setStore_id(storeId);
                    integralConfigModel.setMch_id(storeMchId);
                    integralConfigModel = integralConfigModelMapper.selectOne(integralConfigModel);
                    if (integralConfigModel == null || integralConfigModel.getStatus() == DictionaryConst.WhetherMaven.WHETHER_NO) {
                        logger.debug("【积分】插件未开启/未配置");
                        return null;
                    }
                    autoTeGood = integralConfigModel.getAuto_the_goods();
                    orderFailureDay = integralConfigModel.getOrder_failure();
                    remind = integralConfigModel.getDeliver_remind();
                    commentDay = integralConfigModel.getAuto_good_comment_day();
                    orderAfter = integralConfigModel.getOrder_after();
                    if (StringUtils.isNotEmpty(integralConfigModel.getAuto_good_comment_content())) {
                        autoCommentContent = integralConfigModel.getAuto_good_comment_content();
                    }
                    break;
                case DictionaryConst.OrdersType.ORDERS_HEADER_PS:
                    PreSellConfigModel preSellConfigModel = new PreSellConfigModel();
                    preSellConfigModel.setStore_id(storeId);
                    preSellConfigModel = preSellConfigModelMapper.selectOne(preSellConfigModel);
                    if (Objects.isNull(preSellConfigModel) || preSellConfigModel.getIs_open() == DictionaryConst.WhetherMaven.WHETHER_NO) {
                        logger.debug("【预售】插件未开启/未配置");
                        return null;
                    }
                    autoTeGood = preSellConfigModel.getAuto_the_goods();
                    orderFailureDay = preSellConfigModel.getOrder_failure();
                    remind = preSellConfigModel.getDeliver_remind();
                    commentDay = preSellConfigModel.getAuto_good_comment_day();
                    orderAfter = preSellConfigModel.getOrder_after();
                    if (StringUtils.isNotEmpty(preSellConfigModel.getAuto_good_comment_content())) {
                        autoCommentContent = preSellConfigModel.getAuto_good_comment_content();
                        logger.info("【预售】插件自动回复内容为{}", autoCommentContent);
                    }
                    break;
                case DictionaryConst.OrdersType.ORDERS_HEADER_JP:
                    paramMap.put("storeId", storeId);
                    try {
                        resultMap = httpApiUtils.executeHttpApi("plugin.auction.getPluginConfig", paramMap, MediaType.MULTIPART_FORM_DATA_VALUE);
                        if (!isOpenConfig) {
                            int isOpen = MapUtils.getIntValue(resultMap, "isOpen");
                            if (DictionaryConst.WhetherMaven.WHETHER_NO == isOpen) {
                                logger.debug("【竞拍】插件未开启/未配置");
                                return null;
                            }
                        }
                        orderFailureDay = MapUtils.getInteger(resultMap, "orderFailureDay");
                        remind = MapUtils.getInteger(resultMap, "remind");
                        //竞拍有佣金结算,这里不结算
                        isSettlement = false;
                    } catch (LaiKeAPIException i) {
                        logger.debug("【竞拍】获取配置异常", i);
                        return null;
                    }
                    break;
                case DictionaryConst.OrdersType.ORDERS_HEADER_PT:
                    try {
                        paramMap.put("storeId", storeId);
                        resultMap = httpApiUtils.executeHttpApi("plugin.group.http.getOrderConfig", paramMap, MediaType.MULTIPART_FORM_DATA_VALUE);
                        if (!isOpenConfig) {
                            int isOpen = MapUtils.getIntValue(resultMap, "isOpen");
                            if (DictionaryConst.WhetherMaven.WHETHER_NO == isOpen) {
                                logger.debug("【拼团】插件未开启/未配置");
                                return null;
                            }
                        }
                        orderAfter = MapUtils.getInteger(resultMap, "orderAfter");
                        autoTeGood = MapUtils.getInteger(resultMap, "autoTeGood");
                        commentDay = MapUtils.getInteger(resultMap, "commentDay");
                        autoCommentContent = MapUtils.getString(resultMap, "autoCommentContent");
                        resultMap.put("content", MapUtils.getString(resultMap, "ruleContent"));
                    } catch (LaiKeAPIException i) {
                        logger.debug("【拼团】获取配置异常", i);
                        return null;
                    }
                    break;
                default:
                    return null;
            }

            resultMap.put("isSettlement", isSettlement);
            resultMap.put("remind", remind);
            resultMap.put("commentDay", commentDay);
            resultMap.put("autoTeGood", autoTeGood);
            resultMap.put("orderAfter", orderAfter);
            resultMap.put("orderFailureDay", orderFailureDay);
            resultMap.put("autoCommentContent", autoCommentContent);
        } catch (Exception e) {
            logger.error("根据订单类型获取订单配置 异常:", e);
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_WLYC, "网络异常");
        }
        return resultMap;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean allDelOrder(int storeId, String sNo) throws LaiKeAPIException {
        try {
            int allDelOrder = orderModelMapper.getAllDelOrder(storeId, sNo);
            //用户、商家、平台是否都已经删除订单
            if (allDelOrder == 1){
                //回收订单
                int i1 = orderModelMapper.delOrder(storeId, sNo);
                int i2 = orderDetailsModelMapper.delOrderDetails(storeId, sNo);
                if (i1 <= 0 && i2 <= 0){
                    throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_YWYC, "业务异常", "delOrder");
                }
                logger.debug("用户、商家、平台都已经删除订单,回收订单号：{}", sNo);
            }else {
                return false;
            }
        }catch (LaiKeAPIException l) {
            throw l;
        } catch (Exception e) {
            logger.error("业务异常", e);
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_YWYC, "业务异常", "buyAgain");
        }
        return true;
    }


    @Autowired
    private PublicExpressService publicExpressService;

    @Autowired
    private MessageLoggingModalMapper messageLoggingModalMapper;

    @Autowired
    private ConfiGureModelMapper confiGureModelMapper;

    @Autowired
    private ReturnGoodsModelMapper returnGoodsModelMapper;

    @Autowired
    private PublicPaymentConfigService publicPaymentConfigService;

    @Autowired
    private MchModelMapper mchModelMapper;

    @Autowired
    private ProductListModelMapper productListModelMapper;

    @Autowired
    private ConfigModelMapper configModelMapper;

    @Autowired
    private PublicRefundService publicRefundService;

    @Autowired
    private PublicOrderService publicOrderService;

    @Autowired
    private PublicMchService publicMchService;

    @Autowired
    private RedisUtil redisUtil;

    @Autowired
    private IntegralConfigModelMapper integralConfigModelMapper;

    @Autowired
    private PreSellConfigModelMapper preSellConfigModelMapper;

    @Autowired
    private HttpApiUtils httpApiUtils;
}

